1 /*2 * Created by SharpDevelop. 3 * User: David Huang4 * Date: 2015/7/305 * Time: 16:326 */7 usingSystem;8 9 namespaceLambdaTen { One class Program A { - Public Static voidMain (string[] args) - { the //Anonymous Delegate -func<int,int> del0=Delegate(inti) - { - returni*2; + }; - + //evolved. Afunc<int,int> del1= i=> at { - returni*2; - }; - - //it's evolved again. -func<int,int> Del2 = i = i *2; in - //multiple parameters, multiple lines, writing with Del1. parameter types are either written or not written tofunc<int,int,int> Del3 = (intAintb) = = + { -a++; theb++; * returnA +b; $ };Panax Notoginseng - // thefunc<int,int,int> Del4 = (A, b) + + ++a + + +b; + A theConsole.WriteLine (Del0 (2)); +Console.WriteLine (Del1 (2)); -Console.WriteLine (Del2 (2)); $Console.WriteLine (Del3 (1,2)); $Console.WriteLine (Del4 (1,2)); - - theConsole.Write ("Press any key to continue ..."); -Console.readkey (true);Wuyi } the } -}
Delegates, lambda expressions, and event--lambda expressions