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 ...
随机推荐
- php zip文件内容比較类
php zip 文件比較类,比較两个zip文件的内容,返回新增,删除,及同样的文件列表.临时仅仅支持单层. 需求:上传一个zip文件,zip内有非常多图片文件.须要对图片文件进行一系列非常耗时的处理. ...
- 解决iOS app集成共享QQ场地,微信的朋友,朋友等功能圈,不能采用苹果公司的审计问题
最近提交的应用程序App Store时刻,由于App综合QQ登录.份额QQ场地.微信等功能.被拒绝.很郁闷:在最佳.想想办法,这个问题是可以解决. 当共享平台列表显示.根据推断当前设备被安装在一节Ap ...
- iOS_数据库3_sqlite3基本操作
终于效果图: Sqlite3函数总结 1.打开数据库 int sqlite3_open( const char *filename, // 数据库的文件路径 sqlite3 **ppDb // 数据 ...
- Singleton模式线程相关的(C\C++)
这种需求的最新发展. 我需要一个静态类,无论地方,我可以在线程中调用它public功能对应的功能已经完成. 这个静态类会调用我初始化给它的一个指针,这个指针是与线程一一相应的: 准确来说这样的模式应该 ...
- Spark SQL 源代码分析系列
从决定写Spark SQL文章的源代码分析,到现在一个月的时间,一个又一个几乎相同的结束很快,在这里也做了一个综合指数,方便阅读,下面是读取顺序 :) 第一章 Spark SQL源代码分析之核心流程 ...
- C++使用对象指针
//定义结构 Box.h: #ifndef BOX_H #define BOX_H struct Box{ double length; double width; double height; do ...
- paip.jdk1.4 1.5(5.0) 1.6(6.0) 7.0 8.0特点比较与不同
paip.jdk1.4 1.5(5.0) 1.6(6.0) 7.0 8.0特点比较与不同 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地 ...
- CreateEvent、SetEvent、ResetEvent和WaitForSingleObject
事件对象就像一个开关:它仅仅有两种状态---开和关.当一个事件处于"开"状态.我们称其为"有信号".否则称为"无信号". 能够在一个线程的运 ...
- iOS如何添加照片模拟器(附带诉讼)
刚開始做图片选择时,使用了最笨的办法给iphone模拟器添加照片. 方法一:首先打开safari.然后找到图片.点击图片,保存到本地(iphone): 方法二:拖动本地计算机的随意一张照片到iphon ...
- Java中finally你知多少
首先来问大家一个问题:finally 语句块一定会执行吗? 很多人都认为 finally 语句块是肯定要执行的,其中也包括一些很有经验的 Java 程序员.可惜并不像大多人所认为的那样,对于这个问题, ...