I have 2 different lists:
public class Foo
{
public Int32 Id { get; set; }
}
ICollection<Foo> OriginalCollection
ICollection<Foo> NewCollection
I want to generate 2 lists to be able to foreach them…
- All items that OriginalCollection contains that NewCollection does not (basically, a collection of stuff that was removed).
- All items that OriginalCollection does not contain that NewCollection does (basically, a collection of stuff that was added).
I know I’ll get back an IEnumerable with LINQ, that’s fine since I need to foreach. I just have no idea what my queries should look like…
Update:
I forgot to mention that I did try the Except clause… it failed because the objects are not the same. They only contain the same Id.
So, you want the Complement of the Set.
This post seems to fit your needs:
Quickest way to find the complement of two collections in C#
Or perhaps the Enumerable.Except method:
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.except.aspx