using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LinqDemo
{
class Program
{
static void Main(string[] args)
{
int[] numbers = GenerateLotsOfNumbers(123456789);
var queryResults = from n in numbers
where n > 1000
select n;
Console.WriteLine("大于1000的数字的数量:");
Console.WriteLine(queryResults.Count());
Console.WriteLine("大于1000的数字的最大值:");
Console.WriteLine(queryResults.Max());
Console.WriteLine("大于1000的数字的最小值:");
Console.WriteLine(queryResults.Min());
Console.WriteLine("大于1000的数字的平均值:");
Console.WriteLine(queryResults.Average());
Console.WriteLine("大于1000的数字的和:");
Console.WriteLine(queryResults.Sum(n=>(long)n));
Console.ReadLine();
}
private static int[] GenerateLotsOfNumbers(int count)
{
Random generator = new Random(0);
int[] result = new int[count];
for (int i = 0; i< count; i++)
{
result[i] = generator.Next();
}
return result;
}
}
}
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6849714.html,如需转载请自行联系原作者