Array中的Linq 方法 : Where Count Select
示例数组: int[] intArray = {12,3,24,56,8,65,23};
1. where --> 是筛选方式. 将一个序列中按条件筛选,放到返回的新序列中
如: 将示例数组中 大于30的数提取出来放到新的序列中.
IEnumerable<int> result = intArray.where<int>(x => x > 30);
2.count --> 是计数方式. 得到一个序列中满足条件的元素的个数
如: 得到示例数组中有几个元素大于 20.
int cnt = intArray.Count<int>(x => x > 20);
3.Select --> 将源序列中的所有元素进行操作后的值,放到一个新的序列中
如: 将示例数组中的所有元素 都扩大2倍.得到新的序列
IEnumerable<int> result = intArray.Select<int,int>(x => x * 2);