List之Distinct()
针对数组可以用List.Distinct(),可以过滤掉重复的内容。
针对对象中的某个字段只能用Distinct(IEqualityComparer<T>)
用法:
1 public class AppIndex:BasePage
2 {
3 public void DoGet()
4 {
5 List<test11> list_test = new List<test11>();
6 list_test.Add(new test11() {
7 m=1,
8 v="one"
9 });
10 list_test.Add(new test11()
11 {
12 m = 2,
13 v = "two"
14 });
15 list_test.Add(new test11()
16 {
17 m = 3,
18 v = "three"
19 });
20 list_test.Add(new test11()
21 {
22 m = 4,
23 v = "fornt"
24 });
25 list_test.Add(new test11()
26 {
27 m = 4,
28 v = "fornt"
29 });
30 list_test.Add(new test11()
31 {
32 m = 3,
33 v = "fornt"
34 });
35 var ss = list_test.Distinct(new Comparint());//这里调用
36 this.Add("mylist",new Travel.DAL.AppActive().GetList(BaseCode));
37 }
38 }
39
40 public class test11
41 {
42 public int m { get; set; }
43 public string v { get; set; }
44 }
45 public class Comparint : IEqualityComparer<test11>
46 {
47
48 public bool Equals(test11 x, test11 y)
49 {
50 if (x == null && y == null)
51 return false;
52 return x.m==y.m;
53 }
54
55 public int GetHashCode(test11 obj) {
56 return obj.ToString().GetHashCode();
57 }
58 }
同样table 也可以用这个方法。只要一步ASEnumerable()即可
var _comPresult = _dt.AsEnumerable().Distinct(new DataTableRowCompare());
DataTable _resultDt = _comPresult.CopyToDataTable();
_resultDt.AsEnumerable().ToList().ForEach(
x =>
{
Console.WriteLine(x["id"].ToString() + " " + x["name"].ToString() + " " + x["address"].ToString());
});
List之Distinct()的更多相关文章
- [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 ...
- [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 ...
- [LeetCode] Distinct Subsequences 不同的子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- SQL中distinct的用法
SQL中distinct的用法 1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...
- Oracle 查询语句(where,order by ,like,in,distinct)
select * from production;alter table production add productionprice number(7,2); UPDATE production s ...
- mysql中distinct的用法
本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...
- Distinct Subsequences
https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the numb ...
- distinct 与 group by 去重
例如下表格:表名:fruit id Name Price Num 1 西瓜 10 2 2 西瓜 11 2 3 香蕉 10 3 4 桃子 10 2 当我想获取Name不重复的数据,结果如下 id Nam ...
- 大数据下的Distinct Count(二):Bitmap篇
在前一篇中介绍了使用API做Distinct Count,但是精确计算的API都较慢,那有没有能更快的优化解决方案呢? 1. Bitmap介绍 <编程珠玑>上是这样介绍bitmap的: B ...
- 扩展lamda表达中distinct按照字段去除重复
首先,我们定义一个Student类来测试. public class Student { public int ID { get; set; } public string Name { get; s ...
随机推荐
- SQL声明大全
1.随机选择3记录 select top 3 * from tablename newid() 2.随机选记录 select newid(). 3.删除反复记录 1) delete f ...
- Greenplum+Hadoop学习笔记-14-定义数据库对象之创建与管理模式
6.3.创建与管理模式 概述:DB内组织对象的一种逻辑结构.一个DB内能够有多个模式.在未指定模式时默认放置在public中.能够通过"\dn"方式查看数据库中现有模式: test ...
- poj Firing(最大重量封闭图)
Firing 题目: 要解雇一些人,而解雇的这些人假设人跟他有上下级的关系,则跟他有关系的人也要一起解雇.每一个人都会创造一定的价值,要求你求出在最大的获利下.解雇的人最小. 算法分析: 在这之前要知 ...
- .NET Framework 4.0 以上版本 下载地址
https://msdn.microsoft.com/zh-cn/library/5a4x27ek(v=vs.110).aspx
- Linux的proc文件系统
proc,用户空间和内核空间能够通过该接口通信, 与普通文件不同的是.这些虚拟文件的内容都是动态创建的. proc文件系统是一个伪文件系统,它仅仅存在内存其中,而不占用外存空间. 它以文件系统的方式为 ...
- docker-gitlab(转)
Issues Docker is a relatively new project and is active being developed and tested by a thriving com ...
- CodeForces 69D Dot (游戏+记忆)
Description Anton and Dasha like to play different games during breaks on checkered paper. By the 11 ...
- ORA-01791: not a SELECTed expression 一种是不 bug 的 bug!
[ora11@lixora ~]$ !sql sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Aug 27 09: ...
- NYOJ 1068 ST(段树 为段更新+间隔总和)
ST 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 "麻雀"lengdan用随机数生成了后台数据.可是笨笨的他被妹纸的问题给难住了. .. 已知 ...
- CSDN个人空间能再烂吗?
CSDN空间你敢再烂么? 从CSDN博客跳转到CSDN个人空间的入口还算明显,可是想从个人空间跳转到博客,可真是众里寻他千百度.跳转接口怎么寻都寻不到.根本没有这个跳转的入口.唯一的途径仅仅能从写博文 ...