| 123456789101112131415161718192021222324 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CallCenter.Utility.Linq
- {
- public static class LinqExtend
- {
- 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;
- }
- }
- }
- }
- }
|