http://www.cnblogs.com/A_ming/archive/2013/05/24/3097062.html
public static class LinqEx
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
使用方法
A a111 = new A()
{
F =1,
S=1
};
A a112 = new A()
{
F = 1,
S = 2
};
List<A> __list = new List<A>();
__list.Add(a111);
__list.Add(a112);
IEnumerable<A> __list2 = __list.DistinctBy(p22 => p22.F);
foreach (var a4544 in __list2)
{
}