Tuesday, September 21, 2010
Sunday, September 19, 2010
Tuesday, September 14, 2010
Using LINQ to get a Distinct List
First, create a type comparer:
Then, use it as follows on a List- items:
public class ItemComparer : IEqualityComparer<Item> { #region IEqualityComparer<Item> Members public bool Equals(Item x, Item y) { return x.ItemID == y.ItemID; } public int GetHashCode(Item obj) { return obj.ItemID.GetHashCode(); } #endregion }
Then, use it as follows on a List
IEnumerable<Item> distinctItems =
items.Distinct(new ItemComparer()); items = distinctItems.ToList();
Sunday, September 5, 2010
Subscribe to:
Posts (Atom)