1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceLambdasample7 {8 class Program9 {Ten Static voidMain (string[] args) One { A int[] Myintarray = {1,2,3,4,5 }; - //Accumulator calculates the sum of an array - intresult = Myintarray.aggregate ((Parama, paramb) = Parama +paramb); the intRESULT1 = myintarray.aggregate<int> (Parama, paramb) = Parama +paramb); - intRESULT2 = myintarray.aggregate<int,int> (0, (Parama, paramb) = Parama +paramb); - //recursively computes the sum of an array - intRESULT3 = count (5); +Console.WriteLine ("The Result is:"+result); -Console.WriteLine ("The Result1 is:"+result1); +Console.WriteLine ("The Result2 is:"+result2); AConsole.WriteLine ("The RESULT3 is:"+RESULT3); at - string[] Mystrarray = {"Admin"," Change","Bypage" }; - //string array splicing what to ask - stringstrresult = Mystrarray.aggregate ((Parama, paramb) = Parama +" "+paramb); - //string Array string total length calculation - intRESULT4 = mystrarray.aggregate<string,int> (0, (A, B) = + A +b.length); in //string Array stitching 2, adding the string "Some curries:" - stringSTRRESULT1 = mystrarray.aggregate<string,string> ("Some Curries:", (A, B) = + A +" "+b); to //string Array string total length calculation 2 hovertree.com + intRESULT5 = mystrarray.aggregate<string,string,int> ("Some Curries:", (A, B) = + A +" "+ B, a =a.length); -Console.WriteLine ("The strresult is:"+strresult); theConsole.WriteLine ("The Result4 is:"+result4); * Console.WriteLine (STRRESULT1); $Console.WriteLine ("The RESULT5 is:"+result5);Panax Notoginseng Console.readkey (); - } the + Static intCountintN) A { the if(n = =1) + { - return 1; $ } $ returnn + count (N-1); - } - } the}
Transferred from: http://hovertree.com/h/bjaf/jf9yeju1.htm
Reference: C # Lambda Instance code in the in-depth lambda expression C # generics detailed description
Development technical Article collection: Http://www.cnblogs.com/sosoft/p/kaifajishu.html
C # Getting Started classic lambda