)
            };

//使用匿名方法
            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. iOS项目启动及启动时间优化

    app的启动入口Main函数: int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc ...

  2. NOIP Day1总结

    Day1T1玄学考试 在开始之前,我犯了考前综合症,各种不安各种焦躁. 结果当我去到考场的时候,看了T1...... T1:road 这不是裸的原题么这!我当时心里瞬间想到积木大赛.这明显就是积木大赛 ...

  3. linux学习笔记一:远程连接linux服务器

    环境介绍:win7电脑,通过VM虚拟出linux系统,安装centOS7 通过Xshell连接linux,ftp访问服务器资源. 遇到的问题,ftp连不上linux 解决:linux上安装ftp服务 ...

  4. rpm与yum,at与crontab,sed命令使用

    1.简述rpm与yum命令的常见选项,并举例. rpm——软件包管理系统,它使得在Linux下安装.升级.删除软件包的工作变得容易,并且具有查询.验证软件包的功能. 1)安装选项 命令格式: rpm ...

  5. 学习tp5的第三天(模型)

    一.模型 1.定义基础模型 <?php namespace app\index\model; use think\Model; class User extends Model{ // 设置完整 ...

  6. 树莓派3B+学习笔记:8、安装MySQL

    1.打开终端,先执行: sudo apt-get update 2.再执行: sudo apt-get install mysql-server 输入“y”确认并回车 3.初始化MySQL,输入: s ...

  7. 一个博客萌新的C语言之旅(持续更新中....)

    先更新上一次留下的的C语言练习答案,如下: #include <stdio.h> double mj(double r) { return 3.14*r*r; } int main() { ...

  8. HyperLedger Fabric 1.4 区块链工作过程(2.3)

    区块链的工作过程分交易产生.交易广播.节点计算.获取记账权.记账权广播.接收区块.验证区块和完成记账七个过程. 1) 交易产生:用户向区块链发了一笔交易信息,将产生交易:2) 交易广播:当一笔新交易产 ...

  9. 20155333 2016-2017-2 《Java程序设计》第十周学习总结

    20155333 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 网络概览 两台计算机用于通信的语言叫做"协议".我们只需关心应用层中的协 ...

  10. js日期控件遇到的问题

    一.问题: 在web项目里有很多时候需要使用日期控件来完成相关的功能,但是日期控件的日期格式又和我们的需求不符 那么,就需要我们来自定义日期的格式完成需求 二.解决: 1.取月末: (1)强制取值: ...