Why the function need to run by the delegate?

  • Thread starter Thread starter Jet Leung
  • Start date Start date
J

Jet Leung

Hi:
I had asked how to use delegate in the programming. And now actually I want
to know why and when the function need to run by the delegate?
 
hello,

Hope by now you knew how to use delegates, now question is why and when? Its more relevant to library developers, think of a scenario where you want that implementation of your function ABC() could be provided by any developer consuming your library but you don't want to impose name restrictions on it. Delegates provide an elegant method to register signature of to be implemented method and calling these methods without having type information from called assembly beforehand.
 
You already use delegates all the time when you deal with events in .NET
classes. If you had a bankAccount class and wanted to implement an
AccountOverdrawn event for instance whenever X happens, you'd raise an event
in the get/set accessor and use a delegate as the event handler.
 

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

Back
Top