Distinct
Provides a Distinct method that takes a key selector lambda as parameter.
The .net framework only provides a Distinct method that takes an instance of an implementation of IEqualityComparer
Source
public static IEnumerable<T> Distinct<T, TKey>(this IEnumerable<T> @this, Func<T, TKey> keySelector)
{
return @this.GroupBy( keySelector ).Select( grps => grps ).Select( e => e.First() );
}
Example
var instrumentSet = _instrumentBag.Distinct(i => i.Name);
Author: Martin Rosén-Lidholm
Submitted on: 21 dec 2010
Language: C#
Type: System.Collections.Generic.IEnumerable<T>
Views: 9635