IEnumerable对象的Distinct方法重写

public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)

{

  HashSet<TKey> hashSet = new HashSet<TKey>();

  foreach (TSource element in source)

  {

    if (hashSet.Add(keySelector(element)))

    {

      yield return element;

    }

  }

}

上一篇:word 多级列表设置


下一篇:QPointer,QSharedPointer,QWeakPointer的区别