事件与代理处理程序有什么不同? [英] What is the difference between Events with Delegate Handlers and those without?
本文介绍了事件与代理处理程序有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这有什么区别:
this.btnOk.Click += new System.EventHandler(this.btnOK_Click);
这个?
this.btnOk.Click += this.btnOK_Click;
他们都工作。前者是Visual Studio默认使用的片段。但是,似乎只有广告额外的夸张,或者我是否缺少某些东西?
They both work. The former is what Visual Studio defaults to when you use the snippets. But it seems like it only ads extra verbiage, or am I missing something?
推荐答案
没有区别。省略代理实例化只是语法糖果; C#编译器将为您生成代理实例化。
No difference. Omitting the delegate instantiation is just syntax candy; the C# compiler will generate the delegate instantiation for you under the hood.
这篇关于事件与代理处理程序有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文