📜  C# .NET Core linq Distinct - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:12.252000             🧑  作者: Mango

代码示例3
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;
        }
    }
}