Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delegates and events

Status
Not open for further replies.

luvcloud

Programmer
Apr 23, 2002
24
0
0
MY
is there any advantages in using delegates? I mean, i have a class, lets say classA which handles any events invoked in classB. i could simply have the method in classB, call the method in classA, which is the same as firing the event in classB, which will invoke the method in classA. could someone clarify this...and pls correct me if i'm wrong.

 
Yes you could do that in the above situation, however what if you didn't know what method you needed to call in ClassB?

Delegates are basically signatures for other methods, so lets say you have placed a button on a form, and you have written some code for the OnClick event.
When the Button class actually comes to Raise the onClick event how does it know that your method in your class needs to be called?

If you try and picture your senario.

ClassB has a field called Name. When that field has changed you want to fire an event.
If you had 5 other classes that all wanted to know when Name had changed you would have to write 5 method calls to each of the 5 classes.
With delegates you would just add your method to the delegate and voila it will automatically be called.

Hope that made sense.

CHeers

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top