Wednesday, June 16, 2010

Compare two list using Linq

Here the scenario i have two list with each have student object collection

which has three properties

1.Name
2.Mark
3.Status


Now The
List1 contains .Overall students collection
List2 contains .Total Failed Students collection

Now i want to delete failed students from over all students.

Let find the code using Linq

var passed = list1.Where(x=> !list2.Select(y=>y.status).Contains(x.status)
foreach(var failed in passed)
{
list1.remove(failed);
}
}

No comments:

Post a Comment