C# 给函数传入匿名委托并控制执行指定的次数
public delegate int ConsoleDelegate (int value); public class Test { void ExecuteDelegate (ConsoleDelegate cd, int iterations) { for (int i=1; i <= iterations; i++) { Console.WriteLine ( "Iteration {0}: {1}", i, cd(i) ); } } public static void Main( ) { Test test = new Test(); test.ExecuteDelegate (delegate (int arg) { return arg + arg; }, 5); } }