用新的处理程序附加事件处理程序直接VS它分配 [英] Attaching Eventhandler with New Handler vs Directly assigning it
问题描述
什么是创建一个新的事件处理程序,直接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屋!