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 ...
随机推荐
- QoS令牌桶工作原理
QoS的一个重要作用就是对port流量进行监管,也就是限制port流量.但QoS是怎样做到这点的呢?那就是QoS的令牌桶机制了.以下是在笔者刚刚出版的<Cisco/H3C交换机高级配置与管理技术 ...
- 【Linux】lvm基础操作
新增两块硬盘,来进行实验: [root@jp ~]# fdisk -l Disk /dev/sda: 107.3 GB, 107374182400 bytes 255 heads, 63 sector ...
- CentOS 5 安装Oracle10g
原创作品.离 "深蓝的blog" 博客.欢迎转载.转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlon ...
- 矢量编程——随着MNIST案例
矢量编程使用的所有明确的矢量运算,而不是for周期. 上一节所用的是512*512*10的数据集非常小.我们取的patch非常小(8*8),学来的特征非常少(25).而我又凝视掉了梯度校验(偷懒),所 ...
- PHP关联数组和哈希表(hash table) 未指定
PHP有数据的一个非常重要的一类,就是关联数组.又称为哈希表(hash table),是一种很好用的数据结构. 在程序中.我们可能会遇到须要消重的问题,举一个最简单的模型: 有一份username列表 ...
- Webx框架:Valve详细解释
Valve请求,用于控制过程的操作.它采用责任设计模式链(类别似至struts拦截器).valve阀装置,阀控制水流量(网络请求)趋势. 他们阀门定义. public class MyValve im ...
- Vertica: 基于DBMS架构的列存储数据仓库
介绍 Vertica(属于HP公司),是一个基于DBMS架构的数据库系统,适合读密集的分析型数据库应用,比方数据仓库,白皮书中全名称为VerticaAnalytic Database.从命名中也可以看 ...
- c++日历v1.12版
////////////////////////////新增信息修改功能,未完善. #include<iostream> #include <string> #include& ...
- android--jenkins+gradle+android自动化构建apk步骤(转)
第一步,安装jenkins,这个网上教程挺多的. 第二步,下载并配置gradle.下载地址http://www.gradle.org/ 解压gradle至某路径下,如/usr/local/lib/gr ...
- ZOJ 2412 Farm Irrigation(DFS 条件通讯块)
意甲冠军 两个农田管内可直接连接到壳体 他们将能够共享一个水源 有11种农田 管道的位置高于一定 一个农田矩阵 问至少须要多少水源 DFS的连通块问题 两个相邻农田的管道能够直接连接的 ...