Attaching Eventhandler with New Handler vs Directly assigning it

后端 未结 2 369
名媛妹妹
名媛妹妹 2020-12-03 15:31

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

_gMonitor.CollectionChan         


        
2条回答
  •  抹茶落季
    2020-12-03 15:57

    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!

提交回复
热议问题