1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;56namespaceLambdaSample7{8classPRogram9{10staticvoidMain(string[] args)11{12int[] myIntArray = {1,2,3,4,5};13//累加器计算数组总和14intresult = myIntArray.Aggregate((paramA, paramB) => paramA +paramB);15intresult1 = myIntArray.Aggregate<int>((paramA, paramB) => paramA +paramB);16intresult2 = myIntArray.Aggregate<int,int>(0, (paramA, paramB) => paramA +paramB);17//递归计算数组总和18intresult3 = count(5);19Console.WriteLine("The Result is:"+result);20Console.WriteLine("The Result1 is:"+result1);21Console.WriteLine("The Result2 is:"+result2);22Console.WriteLine("The Result3 is:"+result3);2324string[] myStrArray = {"Admin","Change","ByPage"};25//字符串数组拼接 何问起26stringstrResult = myStrArray.Aggregate((paramA, paramB) => paramA +""+paramB);27//字符串数组字符串总长度计算28intresult4 = myStrArray.Aggregate<string,int>(0, (a, b) => a +b.Length);29//字符串数组拼接2,增加字符串"Some curries: "30stringstrResult1 = myStrArray.Aggregate<string,string>("Some curries:", (a, b) => a +""+b);31//字符串数组字符串总长度计算2 hovertree.com32intresult5 = myStrArray.Aggregate<string,string,int>("Some curries:", (a, b) => a +""+ b, a =>a.Length);33Console.WriteLine("The StrResult is:"+strResult);34Console.WriteLine("The Result4 is:"+result4);35Console.WriteLine(strResult1);36Console.WriteLine("The Result5 is:"+result5);37Console.ReadKey();38}3940staticintcount(intn)41{42if(n ==1)43{44return1;45}46returnn + count(n -1);47}48}49}
转自:http://hovertree.com/h/bjaf/jf9yeju1.htm
参考:C# Lambda 实例代码 深入浅出Lambda表达式 C#泛型详细介绍
开发技术文章收集: http://www.cnblogs.com/sosoft/p/kaifajishu.html