开发者

Subscribe to events

There are two options for subscribing to events:

  1. this.button1.click += new System.EventHandler(this.button1_Click)
  2. 开发者_如何学编程
  3. this.button1.click += this.button1_click

What are the advantages and disadvantages of both techniques?


The second one is easier to read ;-) - they both work in the same way.


The second option is preferred by many - including ReSharper - because it is easier to read and less code. The generated IL code however is the same, so it is purely a question of preference.


Second option is only syntactic sugar for the first one.

You can check generated IL-code and you'll see that compiler generates exactly the same IL-code for both cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜