No, those are equivalent. There are actually six options to consider:
btnHey.Click += new EventHandler(delegate (object obj, EventArgs evn) { ... });
btnHey.Click += new EventHandler(MethodName);
btnHey.Click += delegate (object obj, EventArgs evn) { ... };
btnHey.Click += MethodName;
btnHey.Click += (object obj, EventArgs evn) => ...;
(Expression-bodied lambda)
btnHey.Click += (object obj, EventArgs evn) => { ... };
(Statement lambda)
... where MethodName
is the name of a method with an appropriate signature. The parameters to the lambda expression can also be inferred, leading to even more options...
There can be some subtle differences between them in terms of whether or not a new delegate object is actually created. The options using method group conversions (MethodName
) will always create a new object, at least at the time of writing. With the other options, the compiler may be able to cache a delegate object and reuse it - depending on whether it captures this
or local variables. That's almost never significant, but worth knowing in the rare cases where you need micro-optimization.