根据动作委托的定义,它不返回值但通过值。动作委托 - 声明更正
我传递值Console.WriteLine()
Action<int> an = new Action<int>(Console.WriteLine(3000));
但我仍然收到错误的方法名expected.What是什么问题?
根据动作委托的定义,它不返回值但通过值。动作委托 - 声明更正
我传递值Console.WriteLine()
Action<int> an = new Action<int>(Console.WriteLine(3000));
但我仍然收到错误的方法名expected.What是什么问题?
你会这样的代码是:
Action<int> an = new Action<int>(Console.WriteLine);
an(3000);
克里斯
Action<int>
的构造函数期望您传递一个指针,该指针将一个整数作为参数并不返回任何内容。你传递的不是一个函数,而是一个表达。您既可以定义一个匿名函数或使用现有的一个:
Action<int> an = new Action<int>(t => Console.WriteLine(t));
an(3000);
行动点的方法不仅没有任何参数。
然后,您可以使用它像这样调用操作:
Action<int> action = new Action<int>(Console.WriteLine);
action.Invoke(3000);