C#用匿名方法添加事件的问题
《C#高级编程》中有个例子添加事件时用匿名方法:
btnOne.Click += new EventHandler(lblInfo.Text = "button1 was pressed. ";);
调试时提示错误:
错误 1 应输入 )
错误 2 无效的表达式项“)”
请问这是为什么啊
------解决方案--------------------这才是正确的匿名方法方式:
btnOne.Click += new EventHandler(delegate(object sender,EventArgs e){lblInfo.Text = "button1 was pressed. ";});
//EventHandler委托原型的参数列表必须为:(object sender,EventArgs e)