Difference between delegate and event handler

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);
 
B

Brian Gideon

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.
 
G

Gregory A. Beamer

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! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top