Sco*_*ies 7 delegates action c#-4.0
鉴于以下MSDN示例代码,为什么我不能定义Action委托"内联":
public static void Main(string[] args)
{
Action someAction = () => Console.WriteLine("Hello from the thread pool!");
Task.Factory.StartNew(someAction);
}
Run Code Online (Sandbox Code Playgroud)
...所以"内联"像:
public static void Main(string[] args)
{
Task.Factory.StartNew(Action someAction = () => Console.WriteLine("etc."));
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
斯科特
Tim*_*son 13
这不是有效的C#:
public static void Main(string[] args)
{
Task.Factory.StartNew(Action someAction = () => Console.WriteLine("etc."));
}
Run Code Online (Sandbox Code Playgroud)
改为:
public static void Main(string[] args)
{
Task.Factory.StartNew(() => Console.WriteLine("etc."));
}
Run Code Online (Sandbox Code Playgroud)