class ListDistinctDemo
{
static void Main(string[] args)
{
List personList = new List(){
new Person(3),//重复数据
new Person(3),
new Person(2),
new Person(1)
};

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

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

//使用 Lambda 表达式
List lambdaList = personList.Distinct(new Compare(
(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));

}
}
public class Person
{
public int ID { get; set; }
public string Name { get; set; }

public Person(int id)

{
this.ID = id;
}
}

public delegate bool EqualsComparer(T x, T y);

public class Compare : IEqualityComparer
{
private EqualsComparer _equalsComparer;

public Compare(EqualsComparer<T> equalsComparer)
{this._equalsComparer = equalsComparer;
}public bool Equals(T x, T y)
{if (null != this._equalsComparer)return this._equalsComparer(x, y);elsereturn false;

}

public int GetHashCode(T obj)
{return obj.ToString().GetHashCode();
}

}

C# List Distinct用法相关推荐

  1. mysql中去重的用法_mysql中去重 distinct 用法

    在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count( ...

  2. php distinct 用法,distinct的用法

    1.  Distinct 位置 单独的distinct只能放在开头,否则报错,语法错误 例:SELECT Sid,DISTINCT(Sscore) score from t_student; [SQL ...

  3. 表之sql删除重复数据、查找去除重复数据、DISTINCT用法

    目录 一.查找去除重复数据 二.删除重复数据 三.DISTINCT用法 一.查找去除重复数据 数据如图: id可以理解为uuid,person_sort_code可以理解为唯一的标识,但是唯一标识重复 ...

  4. mysql distinct效率优化_mysql distinct 用法详解及优化

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

  5. tp 中distinct用法

    DISTINCT 方法用于返回唯一不同的值 . 例如: $Model->distinct(true)->field('name')->select(); 生成的SQL语句是: SEL ...

  6. distinct用法及其优化

    在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count( ...

  7. mysql php distinct_mysql distinct用法是什么

    mysql中去重 distinct 用法 在使用mysql时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用disti ...

  8. mysql筛选不重复数据库_mysql的distinct用法-mysql中如何筛选出非重复的数据

    使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有distinct这个关键字来过滤掉多余的重复记录只保留一 条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所 ...

  9. mysql级联distinct_mysql的distinct用法

    使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有 distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所 ...

  10. MySQL拾遗之distinct用法

    目录 阅读源 阅读源 记不住的 MySQL DISTINCT 的用法 ( 上 ) https://www.twle.cn/c/yufei/mysqlfav/mysqlfav-basic-distinc ...

最新文章

  1. onkeypress属性添加报错_亚马逊运营过程中listing常见报错及应对策略汇总
  2. CentOS探索之路2---使用rpm安装JDK
  3. PyCharm 快捷操作
  4. 本地传送命令到远程主机上执行的方法
  5. EOJ_1039_最长连续公共子序列
  6. java面向对象之父类的引用指向子类的对象
  7. LeetCode 173. 二叉搜索树迭代器(中序遍历)
  8. mysql怎么保证热点数据_MySQL里有2000w数据,redis中只存20w数据,如何保证redis中数据都是热点数据...
  9. 【PMP认证考试之个人总结】第 3 章 项目整合管理
  10. 将Nginx加入service服务中
  11. 总结帖:“深度解析:清理烂代码”
  12. 简单的限流保护电路图大全(六款简单的限流保护电路设计原理图详解)
  13. 《博德之门3》的许多设计,还不如上世纪的前作
  14. WXPY自动转发群消息
  15. 《Python数据可视化之Matplotlib与Pyecharts》之K线图
  16. python杨辉三角函数_python杨辉三角输出指定行_使用python打印十行杨辉三角过程详解...
  17. 说说 隋唐演义 等英雄排名
  18. 数据库中char和nchar的区别
  19. [CF765F] Souvenirs
  20. hadoop 集群启动 ERROR: Cannot write datanode pid /tmp/hadoop-user-datanode.pid. 问题的解决

热门文章

  1. 游戏制作之路-愤怒的小鸟-1
  2. 卷积和反卷积核计算公式
  3. c#快捷菜单contextMenuStrip的使用
  4. 360手机论坛刷机包 360手机ROM下载 360手机官网刷机包 360手机刷机包分享下载
  5. TCP 协议灵魂 12 问,巩固你的网路底层基础!
  6. 重磅发布,时隔两月——复旦大学MOSS最新0.0.3版本发布
  7. Power Mode插件的使用
  8. 金融投资心得(个人领悟篇)
  9. 基于Python的基金定投分析: 通过获取过去10年的股市数据分析基金定投的收益率。
  10. 润和软件与华秋达成生态共创合作,共同推动物联网硬件创新