There's no difference. Prior to .NET 2.0, every variable assignments must be of exact type, compilers then didn't infer much. So as to make a work-around, VS 2003 emit new EventHandler
around the function name. That's just my guess. Because..
I tried something now in VS 2008, textBox1.KeyDown += (KeyEventHandler)textBox1_KeyDown
, that also work. It puzzles me why they choose new EventHandler(checkBox1_CheckStateChanged)
, rather than (EventHandler)checkBox1_CheckStateChanged
then. But...
as I don't have VS 2003 in my box anymore, I can't pin down if the casting approach could also work on VS 2003. But afaict, I tried removing new EventHandler
on function name when I used VS 2003 (.NET 1.1), deeming why the need to instantiate (new EventHandler
) a function, delegates are just function pointer under the hood, but it doesn't work.
It's only from .NET 2.0 onwards that C# compiler started to infer as much as possible.
This article http://blueonionsoftware.com/blog.aspx?p=aed2ae46-7548-4e5f-83c6-95e00c6f3649 supported my memory of new EventHandler
prior to .NET 2.0 compilers, it was a compulsary
[EDIT]
The following article goes in depth about subscribing/unsubcribing events, purporting there's a difference between button1.Click += new EventHandler(button1_Click);
and button1.Click += button1_Click;
, but sadly I can't see any difference in IL level though :-(
http://blogs.msdn.com/abhinaba/archive/2005/08/26/456437.aspx