前面讲过委托的知识,本次由委托过渡到Lambda表达式,更易于理解。
 
 1  class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             int[] intA = { 1, 3, 5, 7 };
 6             ProcArray(intA, AddOne);     
 7             foreach (int i in intA)
 8             {
 9                 Console.Write(i + " ");
10             }
11 
12             Console.ReadKey();
13         }
14         private static void ProcArray(int[] intArra, ProcIntArrayHandler procHandler)
15         {
16             for (int i = 0; i < intArra.Length; i++)
17             {
18                 intArra[i] = procHandler(intArra[i]);
19             }
20         }
21 
22         private static int AddOne(int procNum)
23         {
24             return procNum + 1;
25         }
26         private static int AddTwo(int procNum)
27         {
28             return procNum + 2;
29         }
30     }
31     public delegate int ProcIntArrayHandler(int procNum); 
View Code

委托

相关文章:

  • 2021-12-12
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2020-03-15
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2020-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-12-11
  • 2022-12-23
相关资源
相似解决方案