将委托分配给采用 N 个参数但未显式声明参数的函数

Assigning a delegate to a func that takes N parameters without explicitly declaring parameters

给定一个带有 N 个参数的函数,为什么可以向它分配一个没有显式声明任何参数的委托?例如

Func<int, string, object, string, bool> test;
// (1) this makes sense to me
test= delegate (int a, string b, object c, string d) { return true; };

// (2) this also makes sense to me
test= (a,b,c,d)=>true; 

// (3) why does this work? 
test = delegate { return true; }; 

为什么 (3) 有效? (1)、(2)、(3)之间有什么区别吗?我们可以从第三个变体的大括号内访问参数吗?

Why does (3) work?

来自C# programming guide on MSDN

Anonymous methods enable you to omit the parameter list. This means that an anonymous method can be converted to delegates with a variety of signatures


Is there any difference between (1), (2), and (3)?

delegate keyword vs. lambda notation

Can we access the parameters from inside the braces of the third variation?

没有。如果您打算在匿名方法中使用参数,请不要省略参数列表。