我要新建立一个新的委托或者只是添加方法的事件吗? [英] Should I new-up a new delegate or just add the method to an event?

查看:106
本文介绍了我要新建立一个新的委托或者只是添加方法的事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白这2个版本之间的区别是。什么是每一种方法的优点/缺点是什么?



  1。 a.MyEvent + =新MyClass.MyEventDelegate(FireEvent); 

2. a.MyEvent + = FireEvent;


解决方案

第一个在,而C#的所有版本第二只适用于2.0及以上。如果您需要使用C#1.0编译器来编译代码你,去与第一个;否则,我会用更加简洁的版本。所生成的代码应在这两种情况下是相同的。


I don't understand what the difference between these 2 variations are. What is the pros/cons of each approach?

1.  a.MyEvent += new MyClass.MyEventDelegate(FireEvent);

2.  a.MyEvent += FireEvent;

解决方案

The first one works in all versions of C# while the second only works on 2.0 and above. If you need your to compile you code with C# 1.0 compiler, go with the first one; otherwise, I'd use the more concise version. The generated code should be identical in both cases.

这篇关于我要新建立一个新的委托或者只是添加方法的事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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