我可以这样写:为什么不能推断委托参数的类型?
new Thread(new ParameterizedThreadStart((x) => //**parameter type not specified explicitly**
{
for (int j = 0; j < Convert.ToInt32(x); j++)
{
Console.WriteLine(j);
}
})).Start(5);
我可以这样写:
new Thread(new ParameterizedThreadStart(delegate(object x) //**parameter type specified explicitly**
{
for (int j = 0; j < Convert.ToInt32(x); j++)
{
Console.WriteLine(j);
}
})).Start(5);
但我不能这样写:
30 new Thread(new ParameterizedThreadStart(delegate(x) //**parameter type not specified explicitly**
31 {
32 for (int j = 0; j < Convert.ToInt32(x); j++)
33 {
34 Console.WriteLine(j);
35 }
36 })).Start(5);
它提供了多个错误:
- 类型或名称空间找不到名称'x'(缺少使用指令或装配参考吗?) - 第30行
- 当前上下文中不存在名称'x' - 第32行
- 标识符预期 - 行30
为什么委托人不能推断参数类型?语言设计决定?