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

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

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/214346/is-there-an-actual-difference-in-the-2-different-ways-of-attaching-event-handlers">Is在有附加的事件处理程序在C#中的两种不同的方式产生实际差异?

我已经看到了很多code,它是这样的:

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?

推荐答案

二是简写为先;他们将编译为张玉峰IL。

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

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

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

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

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