LINQ标准查询操作符

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace test1
 8 {
 9     class Program
10     {
11 
12         static void Main(string[] args)
13         {
14             string[] words = { "zero", "one", "two", "three", "four" };
15             int[] numbers = { 0, 1, 2, 3, 4 };
16             
17             
18             //聚合
19             Console.WriteLine("合计Sun()=>{0}", numbers.Sum()); //10
20             Console.WriteLine("记数Count()=>{0}", numbers.Count()); //5
21             Console.WriteLine("平均值Average()=>{0}", numbers.Average()); //2
22             Console.WriteLine("long类型合计LongCount()=>{0}", numbers.LongCount(x => x % 2 == 0)); //3(long类型的偶数有3个)
23             Console.WriteLine("统计最小的单词字符的个数=>{0}", words.Min(word => word.Length)); //(one, two)
24             Console.WriteLine("统计最大的单词字符的个数=>{0}", words.Max(word => word.Length)); //5 ("three")
25             Console.WriteLine("{0}", numbers.Aggregate("seed", 
26                 (current, item) => current + item, 
27                 result => result.ToUpper()));//SEED01234
28 
29             
30             
31             Console.ReadKey();
32         }
33     }
34 }

 

posted @ 2014-04-28 00:26  海阔天空XM  阅读(175)  评论(0)    收藏  举报