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?
The second form (implicit conversion from a method group to a delegate type) wasn’t supported before C# 2, so any tutorials etc written before 2005 would have used the first form.
Also, IIRC Visual Studio auto-completes the first form. Personally I prefer the second.