两个结果集数据格式相同,数据结构不同
1. 类定义
public class TestClassA
{
public string Code { get; set; }
public string Name { get; set; }
}
public class TestClassB
{
public string UserCode { get; set; }
public string UserName { get; set; }
}
2.填充数据
var testClassAList = new List
{
new TestClassA { Name="小王",Code = "001"},new TestClassA { Name="小王",Code = "002"},new TestClassA { Name="老王",Code = "003"},new TestClassA { Name="小张",Code = "001"}
};
var testClassBList = new List
{
new TestClassB { UserName="小王",UserCode = "001"},new TestClassB { UserName="小张",UserCode = "002"}
};
3.具体实现
var differentList = classAList.Where(l => !classBList.Any(t => t.UserName == l.Name && t.UserCode == l.Code));
foreach (var item in differentList)
{
Console.WriteLine($"Name: {item.Name} | Code: {item.Code}");
}
原文链接:https://www.f2er.com/note/420995.html