Difference between delegate and event handler

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

I've added a button (button1) on my form. I click on the button, and
automatically a new method is created called, "button1_Click".

I also see that the following line of code is added as well:

button1.Click += new EventHandler(button1_Click);

Just wonder if this line of code is the same as the following:

button1.Click += new delegate(button1_Click);
 
I've added a button (button1) on my form. I click on the button, and
automatically a new method is created called, "button1_Click".

I also see that the following line of code is added as well:

button1.Click += new EventHandler(button1_Click);

Just wonder if this line of code is the same as the following:

button1.Click += new delegate(button1_Click);

The end result is the same.
 
I've added a button (button1) on my form. I click on the button, and
automatically a new method is created called, "button1_Click".

I also see that the following line of code is added as well:

button1.Click += new EventHandler(button1_Click);

Just wonder if this line of code is the same as the following:

button1.Click += new delegate(button1_Click);


And EventHandler() is a type of delegate, so the two are functionally
equivalent.

http://msdn.microsoft.com/en-us/library/system.eventhandler.aspx


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top