Linq的一些用法

本文介绍了C#中List<T>类型的操作方法,包括转换、查找、遍历和包含等常用功能,通过示例展示了如何使用这些方法进行数据处理。

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/archive/2011/10/14/2212307.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值