日期:2014-05-17  浏览次数:20630 次

委托的语法,平时还是不怎么注意.
在winform中,我发现,lambda表达式可以用在 Form的构造函数中,但是不可以自行定义在方法中写.
但是可以注册 new EventHandler
我查了一下 .design
没有发现有什么特点...

------解决方案--------------------
lambda表达式可以用在 Form的构造函数中,但是不可以自行定义在方法中写
什么意思?
Lambda在任何可以写代码的地方都可以写。
e.g:
class Form1
{
    Action<string> showMsg = x => MessageBox.Show(x);
    public Form1() { Action<string> showMsg1 = x => MessageBox.Show(x); }
    void customMethod() { Action<string> showMsg2 = x => MessageBox.Show(x); }
}
------解决方案--------------------
可以写的吧。。。难道是签名不匹配?