用新的处理程序附加事件处理程序直接VS它分配 [英] Attaching Eventhandler with New Handler vs Directly assigning it

查看:126
本文介绍了用新的处理程序附加事件处理程序直接VS它分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是创建一个新的事件处理程序,直接VS分配给它到事件的实际差异,优点和缺点,?

  _gMonitor.CollectionChanged + =新NotifyCollectionChangedEventHandler(OnCollectionChanged);

VS

  _gMonitor.CollectionChanged + = OnCollectionChanged;


解决方案

在C#2.0及以上,它们是相同的。在C#1.2(与.NET 1.1附带的一个),只有第一个语法()编译;-p

第二个语法节省键presses,但VS智能感知通常会建议之首。最终,它使差别很小。我一般用code-样品中的第二个语法网上,仅仅是因为它避免了去在(狭义)列宽!

What is the actual difference, advantages and disadvantages, of creating a new event handler, vs assigning it directly to the event?

_gMonitor.CollectionChanged += new NotifyCollectionChangedEventHandler(OnCollectionChanged);

vs

_gMonitor.CollectionChanged += OnCollectionChanged;

解决方案

In C# 2.0 and above, they are identical. In C# 1.2 (the one that shipped with .NET 1.1), only the first syntax (with new) compiles ;-p

The second syntax saves key presses, but VS intellisense will typically suggest the first. Ultimately, it makes very little difference. I generally use the second syntax in code-samples online, simply because it avoids going over the (narrow) column width!

这篇关于用新的处理程序附加事件处理程序直接VS它分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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