📅  最后修改于: 2022-03-11 14:49:12.252000             🧑  作者: Mango
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;
}
}
}