[英]C# Linq Query for compare two tables
I want linq c# query to compare two tables and list unmatched record from table 1我想要 linq c# 查询来比较两个表并列出表 1 中不匹配的记录
List<MyClass> Unmatched = new List<MyClass>();
foreach (var row in Table_A)
{
if (Table_B.Count(x => x.ID == row.ID) == 0)
Unmatched.Add(row);
}
Something like that?像那样的东西?
It will only check Unmached Table1 to Table2.它只会检查 Unmached Table1 到 Table2。 It doesn't check Table2 to Table1.
它不检查 Table2 到 Table1。
We need more details.我们需要更多细节。
The last line of code compares the elements of two lists and with !最后一行代码将两个列表的元素与 ! Contains keep only the unmatched elements of the first list and added to the new Unmathced list:
Contains 仅保留第一个列表中不匹配的元素并添加到新的Unmathced列表中:
List<string> table_1 = new List<string>() { "panos", "mitsos", "alex", "niki" };
List<string> table_2 = new List<string>() { "panos", "mitsos", "alexandros", "maria" };
List<string> UnmatchedList= new List<string>();
UnmatchedList = table_1.Where(x => !table_2.Contains(x)).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.