65.9K
CodeProject is changing. Read more.
Home

Diff two lists

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Dec 14, 2010

CPOL
viewsIcon

5205

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 GetUpdatedList(this List oldList, List newList) where T : class { List itemsToAdd = new List(); List itemsToRemove = new List(oldList); foreach (var item in newList) { if (oldList.Exists(t=>t==item)) { itemsToRemove.Remove(item); } else { itemsToAdd.Add(item); } } return itemsToAdd.Concat(itemsToRemove).ToList(); } }