C#不能像javascript直接传递和返回函数类型的参数,需要以委托方式才可以
class Program { static void Main(string[] args) { var numbd1 = GetNumBuilder(); var numbd2 = GetNumBuilder(); Console.WriteLine("--------数字构造器1号---------"); for (int i = 0; i < 10; i++) { Console.WriteLine(numbd1()); } Console.WriteLine("--------数字构造器2号---------"); for (int i = 0; i < 10; i++) { Console.WriteLine(numbd2()); } } public static Func<int> GetNumBuilder() { int i = 0; Func<int> f = () => { return i++; }; return f; } }