1 /*
 2  * 由SharpDevelop创建。
 3  * 用户: David Huang
 4  * 日期: 2015/7/30
 5  * 时间: 16:32
 6  */
 7 using System;
 8 
 9 namespace Lambda
10 {
11     class Program
12     {
13         public static void Main(string[] args)
14         {
15             //匿名委托
16             Func<int,int> Del0=delegate(int i)
17             {
18                 return i*2;
19             };
20             
21             //进化了
22             Func<int,int> Del1= i=>
23             {
24                 return i*2;
25             };
26             
27             //又进化了
28             Func<int,int> Del2 = i => i * 2;
29               
30             //多个参数,多行,写法同Del1。参数类型要么都写,要么都不写
31             Func<int,int,int> Del3 = (int a, int b) =>
32             {
33                 a++;
34                 b++;
35                 return a+b;
36             };
37             
38             //
39             Func<int,int,int> Del4 = (a, b) => ++a + ++b;
40             
41             
42             Console.WriteLine(Del0(2));
43             Console.WriteLine(Del1(2));
44             Console.WriteLine(Del2(2));
45             Console.WriteLine(Del3(1,2));
46             Console.WriteLine(Del4(1,2));
47             
48             
49             Console.Write("Press any key to continue . . . ");
50             Console.ReadKey(true);
51         }
52     }
53 }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-05-25
  • 2022-02-04
  • 2021-08-08
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2021-11-02
  • 2021-06-28
相关资源
相似解决方案