一、集合操作
1、去除重复的项-Distinct()
string[] planets = { "Mercury", "Venus", "Venus", "Earth", "Mars", "Earth" };
IEnumerable<string> query = from planet in planets.Distinct()
select planet;
query
另外的一种写法
再另外一种就是tohashset,异曲同工,更符合数学的思想
2、在集合A但不在集合B中-Except()
string[] myset1 = {"a","b","c","d","e"};
string[] myset2 = {"a","b","c","d"};
myset1.Except(myset2)
3、集合交集 - Intersect()
string[] set1 = { "a", "b", "c", "d" };
string[] set2 = { "b", "d", "e", "f" };
set1.Intersect(set2)
4、集合并集——Union()
string[] set1 = { "a", "b", "c", "d" };
string[] set2 = { "b", "d", "e", "f" };
set1.Union(set2)
二、列表推导-Select()
从一个列表,按照给定的方法,生成新的列表
用列表推导,如何从第一张表(实际上是一个数组)生成第二张表
Enumerable.Range(1, 5).Select(x=> Tuple.Create(x,x * 2,x*x+3))
三、Zip()
三个列并成一个表
表中每一行是一个什么类型呢
使用场合:
之前用的最多的地方是:列表推导的时候,从三个list中,取值,经过计算后,返回一个list