using System.Collections.Generic;
public static void Main()
var items = new List<Foo>
var enumerable = items.DistinctBy(f => f.MyProperty);
Console.WriteLine("Count: {0}", enumerable.Count());
Console.WriteLine("Count: {0}", enumerable.Count());
public int MyProperty { get; set; }
public static class Extensions
public static IEnumerable<T> DistinctBy<T, TKey>(this IEnumerable<T> items, Func<T, TKey> property)
if (items == null || property == null)
return Enumerable.Empty<T>();
var known = new HashSet<TKey>();
return items.Where(element => known.Add(property(element)));