Click here to Skip to main content
15,891,431 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Diff two lists

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
20 Dec 2010CPOL 5.1K   1  
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)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --