Questin on Delgates

J

jw56578

I've read a basic tutorial on delegates but am still unclear about
them. Can someone explain what the point of using them is. I don't
completely understand them yet nor the reason for their use.
Thanks
 
J

Joe Mayo [C# MVP]

They're very commonly used with GUI events. i.e. When the user clicks a
button, the button automatically fires a Click event. If you want code to
respond to that Click event, you have to be able to notify the button to
call your method with that code when the Click event occurs. This is where
the delegate comes in - it provides the mechanism to tell the Click event to
call your method. So, you will define a delegate that refers to your method
and hook it up to the button's click event. Every time a user interacts
with some control in your GUI, an event will fire and any methods that have
been hooked up to that event, via a delegate, will be called.

Joe
 

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