书里在讨论到事件中使用匿名方式时举了下面三个例子:
btnOne.Click += new EventHandler( lblInfo.Text = "button One was pressed.";);
btnTwo.Click += new EventHandler( lblInfo.Text = "button Two was pressed.";);
......
可是匿名方法不是这么用的,事实上这几行代码也无法编译通过。
应该改成类似于
this.btnEvent.Click += new System.EventHandler(delegate(object sender, EventArgs e)
{
MessageBox.Show("I have no name", "AnonymousMethodOfbtnEvent", MessageBoxButtons.OKCancel);
});