Tuesday, October 1, 2013

Compare 2 list objects

You could try something like this:



List<Employee> oldEmp = new List<Employee>();
List<Employee> newEmp = new List<Employee>();
oldEmp.Add(new Employee
{
EmployeeId=1,
Description="A",
Summary = "1"
});
newEmp.Add(new Employee
{
EmployeeId = 1,
Description = "A",
Summary = "1"
});
oldEmp.Add(new Employee
{
EmployeeId = 2,
Description = "B",
Summary = "1"
});
newEmp.Add(new Employee
{
EmployeeId = 2,
Description = "B",
Summary = "2"
});
oldEmp.Add(new Employee
{
EmployeeId = 3,
Description = "C",
Summary = "1"
});
newEmp.Add(new Employee
{
EmployeeId = 3,
Description = "C",
Summary = "1"
});

List<Employee> difference = oldEmp.Where(x => !newEmp.Any(x1 => x1.Summary.Equals(x.Summary)))
.Union(newEmp.Where(x => !oldEmp.Any(x1 => x1.Summary.Equals(x.Summary)))).ToList();


No comments:

Post a Comment