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?
Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.
Your question is not completely specified but I assume that you are 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With