Click here to Skip to main content
12,298,927 members (50,617 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.5K views
2 bookmarked
Posted

Diff two lists

, 19 Dec 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
public static class ListHelper{ public static List GetUpdatedList(this List oldList, List newList) where T : class { List itemsToAdd = new List(); List itemsToRemove = new List(oldList); foreach (var item in newList) { if...
public static class ListHelper
{
      public static List<t> GetUpdatedList<t>(this List<t> oldList,
            List<t> newList) where T : class
      {
            List<t> itemsToAdd = new List<t>();
            List<t> itemsToRemove = new List<t>(oldList);
            foreach (var item in newList)
            {
                  if (oldList.Exists(t=&gt;t==item))
                  {
                        itemsToRemove.Remove(item);
                  }
                  else
                  {
                        itemsToAdd.Add(item);
                  }
            }
            return itemsToAdd.Concat(itemsToRemove).ToList();
      }
}

License

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

Share

About the Author

Chris Hey
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 19 Dec 2010
Article Copyright 2010 by Chris Hey
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid