开了网站建设公司 如何接业务,百度网站权重查询,水果网络营销策划书,seo推广软件下载一、select用法 Linq中的select可以便捷使我们的对List中的每一项进行操作#xff0c;生成新的列表。
var ttlist.select(pp10);
//select括号内为List中的每一项#xff0c;p10即为对每一项的操作#xff0c;即对每项都加10生成新的List
用法实例#xff1a;
1、la…一、select用法 Linq中的select可以便捷使我们的对List中的每一项进行操作生成新的列表。
var ttlist.select(pp10);
//select括号内为List中的每一项p10即为对每一项的操作即对每项都加10生成新的List
用法实例
1、lambda表达式
int[] array { 1,5,6,7,6,9,12,2,7,6,33};
Listint l1 new Listint(array);
var t1 l1.Select((p)p10);
foreach (var item in t1)
{Console.WriteLine(item);
}
输出结果为 2、Linq语法 ListStudent_1 stuList new ListStudent_1(){new Student_1(){ID1,NameJohn,Chinese92,Math88,English92},new Student_1(){ID2,NameMary,Chinese87,Math94,English82},new Student_1(){ID3,NameKangKang,Chinese89,Math91,English96},new Student_1(){ID4,NameMaria,Chinese88,Math65,English94},new Student_1(){ID5,NameBen,Chinese70,Math91,English82},};var t1 from e in stuList select e.English;foreach (var item in t1){Console.WriteLine(item);} 二、SelectMany用法 在C# Linq中SelectMany方法用于将一个集合中的每个元素转换为另一个集合并将所有转换后的集合合并为一个集合。
ListListint list new ListListint()
{new Listint() { 1, 2, 3 },new Listint() { 4, 5, 6 },new Listint() { 7, 8, 9 }
};var result list.SelectMany(x x);foreach (var item in result)
{Console.WriteLine(item);
} 三、where用法
where在Linq中主要进行对数据筛选并且生成新的List。 ListStudent_1 stuList new ListStudent_1(){new Student_1(){ID1,NameJohn,Chinese92,Math88,English92},new Student_1(){ID2,NameMary,Chinese87,Math94,English82},new Student_1(){ID3,NameKangKang,Chinese89,Math91,English96},new Student_1(){ID4,NameMaria,Chinese88,Math65,English94},new Student_1(){ID5,NameBen,Chinese70,Math91,English82},};//lambda表达式 表达式内部填的是判断条件var t1 stuList.Where(p p.English 88);// Linq 语句var t1 from e in stuList where e.English 82 select e;
需要注意的是Lambda表达式中不需要select结尾但Linq 语句必须是select结尾否则报错
运行结果为 参考文献:
C#的LINQ select查询、where过滤、group分组、join关联_c# t.select().join_小龙在山东的博客-CSDN博客