)
            };

//使用匿名方法
            List<Person> delegateList = personList.Distinct(new Compare<Person>(
                delegate(Person x, Person y)
                {
                    if (null== x ||null== y) returnfalse;
                    return x.ID == y.ID;
                })).ToList();

delegateList.ForEach(s => Console.WriteLine(s.ID));

//使用 Lambda 表达式
            List<Person> lambdaList = personList.Distinct(new Compare<Person>(
                (x, y) => (null!= x &&null!= y) && (x.ID == y.ID))).ToList();

lambdaList.ForEach(s => Console.WriteLine(s.ID));

//排序
            personList.Sort((x, y) => x.ID.CompareTo(y.ID));
            personList.ForEach(s => Console.WriteLine(s.ID));

}
    }
    publicclass Person
    {
        publicint ID { get; set; }
        publicstring Name { get; set; }
       
        public Person(int id)
        {
            this.ID = id;
        }
    }

publicdelegatebool EqualsComparer<T>(T x, T y);

publicclass Compare<T> : IEqualityComparer<T>
    {
        private EqualsComparer<T> _equalsComparer;

public Compare(EqualsComparer<T> equalsComparer)
        {
            this._equalsComparer = equalsComparer;
        }

publicbool Equals(T x, T y)
        {
            if (null!=this._equalsComparer)
                returnthis._equalsComparer(x, y);
            else
                returnfalse;
        }

publicint GetHashCode(T obj)
        {
            return obj.ToString().GetHashCode();
        }
    }

List<T>.Distinct()的更多相关文章

  1. [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串

    Given a string, find the length of the longest substring T that contains at most k distinct characte ...

  2. [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

    Given a string S, find the length of the longest substring T that contains at most two distinct char ...

  3. [LeetCode] Distinct Subsequences 不同的子序列

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  4. SQL中distinct的用法

    SQL中distinct的用法   1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...

  5. Oracle 查询语句(where,order by ,like,in,distinct)

    select * from production;alter table production add productionprice number(7,2); UPDATE production s ...

  6. mysql中distinct的用法

    本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...

  7. Distinct Subsequences

    https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the numb ...

  8. distinct 与 group by 去重

    例如下表格:表名:fruit id Name Price Num 1 西瓜 10 2 2 西瓜 11 2 3 香蕉 10 3 4 桃子 10 2 当我想获取Name不重复的数据,结果如下 id Nam ...

  9. 大数据下的Distinct Count(二):Bitmap篇

    在前一篇中介绍了使用API做Distinct Count,但是精确计算的API都较慢,那有没有能更快的优化解决方案呢? 1. Bitmap介绍 <编程珠玑>上是这样介绍bitmap的: B ...

  10. 扩展lamda表达中distinct按照字段去除重复

    首先,我们定义一个Student类来测试. public class Student { public int ID { get; set; } public string Name { get; s ...

随机推荐

  1. cannot find module 'xxx' 解决办法

    先将node_module文件夹删掉 工程目录下输入命令:npm clean cache 查看package.json里有没有依赖项,有的话npm install 没有就npm install exp ...

  2. Redis 之复制-初入江湖

    一.前言 在分布式系统中,为了解决单点问题,通常会把数据复制多个副本部署到其他机器,满足故障恢复合负载均衡等需求.Redis也是如此,它为我们提供了复制的功能,实现了相同数据的多个Redis副本.复制 ...

  3. 如何在HHDI中调用Java文件

    创建执行JS语句任务,在脚本中输入相关代码,两种写法: ------------------------写法一 // 直接调用类的路径 var now = com.haohe.utils.DateUt ...

  4. 分布式日志收集框架Flume

    分布式日志收集框架Flume 1.业务现状分析 WebServer/ApplicationServer分散在各个机器上 想在大数据平台Hadoop进行统计分析 日志如何收集到Hadoop平台上 解决方 ...

  5. /usr/bin/python与/usr/bin/env python的区别

    Infi-chu: http://www.cnblogs.com/Infi-chu/ /usr/bin/env python执行时,先查找python解释器的路径,然后执行./usr/bin/pyth ...

  6. 20155210 2016-2017-2《Java程序设计》课程总结

    20155210 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:你期望的师生关系 预备作业2:做中学 预备作业3:虚拟机安装 第一周作业:教材 ...

  7. 2017-2018-1 20155327 《信息安全系统设计基础》课堂测试&课下作业

    2017-2018-1 20155327 <信息安全系统设计基础>课堂测试&课下作业 学习使用stat(1),并用C语言实现 提交学习stat(1)的截图 man -k ,grep ...

  8. 20155330 2016-2017-2《Java程序设计》课程总结

    20155330 2016-2017-2<Java程序设计>课程总结 目录 每周作业链接汇总 实验报告链接汇总 代码托管 课堂项目实践 课程收获与不足 问卷调查 给出你的总结中涉及到的链接 ...

  9. 人脸识别引擎SeetaFaceEngine简介及在windows7 vs2013下的编译

    SeetaFaceEngine是开源的C++人脸识别引擎,无需第三方库,它是由中科院计算所山世光老师团队研发.它的License是BSD-2. SeetaFaceEngine库包括三个模块:人脸检测( ...

  10. 【HEOI2016】排序

    题面 题解 这题好神仙啊... 我们二分这个位置上的数, 然后当\(val[i] \geq mid\)的位置设为\(1\),否则为\(0\) 这样一来,这道题就变成了一个\(01\)序列排序,所以就可 ...