[英]C# Linq Query for compare two tables
我想要 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);
}
像那样的东西?
它只会检查 Unmached Table1 到 Table2。 它不检查 Table2 到 Table1。
我们需要更多细节。
最后一行代码将两个列表的元素与 ! 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.