我希望linq c#查询比较两个表并列出表1中不匹配的记录
答案 0 :(得分:0)
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);
}
类似的东西吗?
它将仅检查未匹配的表1到表2。 它不会检查Table2到Table1。
我们需要更多详细信息。
答案 1 :(得分:-1)
代码的最后一行将两个列表的元素与进行比较!包含仅保留第一个列表中不匹配的元素,并将其添加到新的 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();