int[] num = { 1, 3, 5, 7, 2, 3, 4, 5, 6, 7, 90};
IEnumerable<int> num1= from n in num where n < 5 select n;
foreach (var a in num1) {
Console.WriteLine("a<5 {0}",a);
}
方法语法
var num2 = num.Where(x => x < 6);
foreach (var b in num2)
{
// Console.WriteLine("b<6 {0}", b);
}
方法
int num1Count = (from n in num where n < 5 select n).Count();
Console.WriteLine("计算nums中<5的个数 {0}",num1Count);
//sum 求和
//Average 求平均数
//Max/Min 最大值最小值
//First/Last 第一个最后一个
//Distinct 去重
IEnumerable<int> num1Count = (from n in num where n < 5 select n).OrderByDescending(x=>x);
foreach (var J in num1Count) {
Console.WriteLine(J);
}
OrderBy/OrderByDescending 顺序/逆序
查询语法 int[] num = { 1, 3, 5, 7, 2, 3, 4, 5, 6, 7, 90}; IEnumerable<int> num1= from n in num where n < 5 select n; foreach (var a in num1) { Console.WriteLine("a<5 {0}",a); }方法语法 var num2 = nu