using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AllBase.Extension { public static class LinqExtension { public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) { HashSet seenKeys = new HashSet(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(element))) { yield return element; } } } } }