Skip to content

Instantly share code, notes, and snippets.

@atheken
Created November 26, 2009 15:36
Show Gist options
  • Save atheken/243516 to your computer and use it in GitHub Desktop.
Save atheken/243516 to your computer and use it in GitHub Desktop.
public static IEnumerable<T> Distinct(this IEnumerable<T> set, Func<T,U> propertySelector)
{
HashSet<U> distinct = new HashSet<U>();
foreach(var a in set)
{
var key = propertySelector.Invoke(a);
if(!distinct.Contains(key))
{
distinct.Add(key);
yield return a;
}
}
yield break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment