挂起事件处理程序的这两种语法有什么区别? [英] What is the difference between these two syntaxes for hooking up an event handler?

查看:99
本文介绍了挂起事件处理程序的这两种语法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在C#中附加事件处理程序的两种不同的方法有实际的区别吗?

$ b我已经看到很多代码如下:

  foo.Drop + = new DragEventHandler(fooHandler); 

但是过去,我一直这样做:

  foo.Drop + = fooHandler; 

这两种语法有区别吗?如果是这样,那么长期的做法有什么好处吗?

解决方案

第二个是第一个的缩写;他们将编译为indentical IL。



但是,第二种语法是C#2.0的新功能; C#1只支持第一个。


Possible Duplicate:
Is there an actual difference in the 2 different ways of attaching event handlers in C#?

I've been seeing a lot of code that looks like this:

foo.Drop += new DragEventHandler(fooHandler);

But in the past, I've always done this:

foo.Drop += fooHandler;

Is there a difference between these two syntaxes? If so, is there any advantage to doing it the long way?

解决方案

The second is shorthand for the first; they will compile to indentical IL.

However, the second syntax is new to C# 2.0; C# 1 only supports the first.

这篇关于挂起事件处理程序的这两种语法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆