views:

316

answers:

2

I have two list of members like this:

Before: Peter, Ken, Julia, Tom

After: Peter, Robert, Julia, Tom

As you can see, Ken is is out and Robert is in.

What I want is to detect the changes. I want a list of what has changed in both lists. How can linq help me?

+3  A: 

Your question is not copmletely specified but I assume that you looking for the differences as sets (that is, ordering does not matter). If so, you want the symmetric difference of the two sets. You can achieve this using Enumerable.Except:

before.Except(after).Union(after.Except(before));
Jason
+1  A: 

Another way:

before.Union(after).Except(before.Intersect(after))
Manu