C# 按条件去重
标签:ash common sharp 条件 ext ret arp source sele
添加这段代码即可。
public class CommonEqualityComparer : IEqualityComparer
???{
??????private Func keySelector;
??????public CommonEqualityComparer(Func keySelector)
??????{
?????????this.keySelector = keySelector;
??????}
??????public bool Equals(T x, T y)
??????{
?????????return EqualityComparer.Default.Equals(keySelector(x), keySelector(y));
??????}
??????public int GetHashCode(T obj)
??????{
?????????return EqualityComparer.Default.GetHashCode(keySelector(obj));
??????}
???}
???public static class DistinctExtensions
???{
??????public static IEnumerable Distinct(this IEnumerable source, Func keySelector)
??????{
?????????return source.Distinct(new CommonEqualityComparer(keySelector));
??????}
???}
参考链接:
https://cloud.tencent.com/developer/article/1344620
C# 按条件去重
标签:ash common sharp 条件 ext ret arp source sele
原文地址:https://www.cnblogs.com/chendeqiang/p/12861597.html
文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
文章标题:
C# 按条件去重
文章链接:http://soscw.com/essay/60691.html
评论