LINQ笔记-AsParallel()、SelectMany()、SequenceEqual()、Zip()

AsParallel()

并行化操作,大集合使用,提高速度

personList.AsParallel().Sum(p => p.CompanyID);

SelectMany()

合并集合成员

Dictionary<int, List<string>> dict = new Dictionary<int, List<string>>();
IEnumerable<string> values = dict.SelectMany(d => d.Value); 
var list2 = teachers.SelectMany(teacher => teacher.Students);

SequenceEqual()
逐一比较两个集合中的元素,如果相同就返回true,元素位置不同也不行

List<int> intList1 = new List<int>() { 1, 2, 3 };
List<int> intList2 = new List<int>() { 2,1,3};            
Console.WriteLine(intList1.SequenceEqual(intList2));//false

Zip()
将指定函数应用于两个序列的对应元素,以生成结果序列

 IEnumerable<int> result = intList1.Zip(intList2, (i, j) => {
                return i + j;
            });

AsQueryable()

将Lambda表达式作为数据存储起来,Expression表达式

原文地址:https://www.cnblogs.com/fanfan-90/p/12114625.html