找出两个列表中的差异 [英] Find the difference in two List

查看:89
本文介绍了找出两个列表中的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想知道找到两个列表之间差异的有效方法是什么?



假设我有一个员工类。

Hello I would like to know what is the efficient way to find the differences between two list?

Let''s say I have a Employee Class.

public class Employee
{
    public int EmployeeID { get; set; }
    public int DepartmentID { get; set; }
    public DateTime StartDate { get; set; }
    public int SupervisorID { get; set; }
    public string FullName { get; set; }        
    public DateTime EndDate { get; set; }
    public string Title { get; set; }
    public string Address { get; set; }
}



我有两个清单


I have two lists

List<Employee> empInDB1 = new List<Employee>();
List<Employee> empInDB2 = new List<Employee>();



东西循环遍历行/列表中的每个员工匹配EmployeeID中的员工并比较每个字段以及是否更改并将其添加到新列表中?


Something loops through the rows/each employee in the list match the employee from EmployeeID and compare each field and if it is changed and add it to a new list?

var changedData = empInDB1.Intersect(empInDB2);

但是我被困了可以有人带我到解决方案。在此先感谢。

But I am stuck can someone lead me to the solution. Thanks in advance.

推荐答案

尝试

Try
var changedData = empInDB1.Except(empInDB2);


查看类似的讨论这里 [ ^ ]
Have a look on similar discussion here[^]


我会使用除了 [ ^ ]方法(参见代码示例)。
I would use the Except[^] method (see the code samples).


这篇关于找出两个列表中的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆