Linq的一些用法

List<Student>  stuList;(这个里面假设已经有值了,Student 里面有ID,Name)

ConvertAll:

List<string> strNameList = stuList.ConvertAll(p=>p.Name).ToList();//这样就将Student中的名字取出来了。

FindAll:

List<Student> stuList1 = stulist.FindAll(p=>p.Name = "");

ForEach:

List<Student> stuList1 = stulist.ForEach(p=>p.Name = "aaaaa");

List<Student> stuList2 = new List<Student>();

stulist.ForEach(p=>stuList2.Add(p));

Contains:

var subset = from g in s where g.Contains(" ") orderby g select g;

int[] result = (from i in intArray where i > 30 orderby i select i).ToArray<int>();//直接将查询到结果。

int count = (from i in result select i).Count<int>();//数量

原文地址:https://www.cnblogs.com/pnljs/p/2212307.html