linqtoobject基本用法

linqtoobject基本用法

ID:34724120

大小:73.68 KB

页数:3页

时间:2019-03-10

linqtoobject基本用法_第1页
linqtoobject基本用法_第2页
linqtoobject基本用法_第3页
资源描述:

《linqtoobject基本用法》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、LinQToObject基本用法.Linq的基本用法:Sort ,OrderBy,Skip,Take,Where,Compare,Join,Distinct,InsertRange等关键词Select用法  varselectedItems=fromiteminitemswhereitem.ParentID==parentIDorderbyitem.SortIndex descending,item.Nameascending selectitem;0.1where:varlist=collection.Where(t=>(txtCustomerNa

2、me.Text.Trim().Length==0

3、

4、t.ClientName.ToUpper().IndexOf(txtCustomerName.Text.Trim().ToUpper())>=0)); //根据条件查询,如果txtCustomerName中有值则匹配collection中的ClientName是否包含这个txtCustomerName的值10.1LInq递归实现定义function     privateBuildExpression(IEnumberableenumberableList){...}returnfa

5、ctory=>           {  //递归实现的function                 BuildExpression(factory);             };一、LinQToObject主要使用在一些array,list,collection,IEnumerable等数组上面,varlist=newList(); varlist2=newList();1.01list.Select(t=>t.CreateDate).SeperateToString(",");  //selectcreatedate字段集合并组

6、成string返回1.02 list.Select(t=>newDataEntity{Name=t.Name,Value=t.Value});   //selectTypeOf(list)类型中的某些字段到新的DataEntity实例中1.11list.OrderBy(entity=>entity.CreateDate);  //entity表示T的一个实例,按照createdate顺序排列,反之则使用listOrderByDescing1.12selectedItems.OrderBy(entity=>entity.SortIndex).ThenB

7、y(entity=>entity.name); //多个字段排序1.2  list.Sort( (x,y)=>StringComparer.CurrentCultureIgnoreCase.Compare(x.CreateDate,y.CreateDate));//x,y表示T的一个实例,x在y前面表示顺序排列,如果变为Compare(y.CreateDate,x.CreateDate)表示倒序排列1.3list.Skip(count)  //count表示跳过count个数据 处理分页可以使用list.Skip((page-1)*pageSize)

8、.Take(pageSize);1.4list.Take(count) //count表示选取count个数据实例1(按照createdate排序,并选取前n个T类型的集合):list.OrderBy(entity==>entity.CreateDate).Take(n).ToList();1.5list.Distinct();  //删除重复项,list必须为一维数据组1.6list.Count();  //list数字的记录条数1.6.1 list.Count(item=>item.Name=='test') //查询list中name为t

9、est的记录条数1.7 list.Sum();  //合计,list必须为一维数组1.7.1 list.Sum(item=>item.Quantity);   //合计,合计list中的quantity字段1.8list.Min();  //list中的最小值或记录1.8.1 list.Select(item=>item.Quantity).Min()  //或者list中数量最少的记录1.8.2 list.Min(item=>item.Quantity)  //或者list中数量最少的记录1.8list.InsertRange(0,list2)  

10、//在list的指定位置插入list21.9list.ForEach(item=>item.Quantity

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。