/// <summary>
/// 根据集合中某个字段排除重复项
/// </summary>
public static class DistinctExtension
{
public static IEnumerable<TSource> DistinctByFiled<TSource, TKey>(this IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector)
{
HashSet<TKey> hashKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (hashKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
//调用
list.DistinctByFiled(x => x.FiledID);