What the purpose/difference in using an event-type constructor

Posted by phq on Stack Overflow See other posts from Stack Overflow or by phq
Published on 2010-06-07T22:19:02Z Indexed on 2010/06/07 22:22 UTC
Read the original article Hit count: 179

Filed under:
|

In all examples I can find as well as the automatically generated code i Visual Studio, events are set using the following code:

button1.Click += new System.EventHandler(this.button1_Click);

But I can also write it visually cleaner by omitting the constructor wrapper:

button1.Click += this.button1_Click;

Which also compile fine.

What is the difference between these two? And why is the first one mostly used/preferred?

© Stack Overflow or respective owner

Related posts about c#

Related posts about events