Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Diff two lists

5.00/5 (3 votes)
20 Dec 2010CPOL 5.2K  
I'd use this only because I find 2 lines of code easier to read than all of the others above. var itemsToRemove = oldList.Except(newList).ToArray(); var itemsToAdd = newList.Except(oldList).ToArray();This will work as long as each list is actually a set. Given your description of...
I'd use this only because I find 2 lines of code easier to read than all of the others above.

var itemsToRemove = oldList.Except(newList).ToArray();
var itemsToAdd = newList.Except(oldList).ToArray();


This will work as long as each list is actually a set. Given your description of the original problem, it sounds like this is true.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)