Help understanding user created Delegates

  • Thread starter Thread starter RSH
  • Start date Start date
R

RSH

I have been looking at delegates lately. I have seen several articles
explaining them but I'm having a hard time understanding why I would use a
delegate over a traditional function or sub. Could someone please help me
understand why i would use a delegate in day to day use, over a function or
sub?

Thank you for your time!
Ron
 
Well, I hope this helps a little. Here's how I use them a lot.
When I add controls at runtime, I use the AddHandler VB function, often, to
direct a call of a particular event at one routine I've written to handle
the group of controls. This enables me to write only one function to handle
the event of the group of controls I've added. This is a very nice feature
that is enabled via delegates.

Another way delegates can be used, apriori .NET 2.0, is perhaps in
collections. Buy using a delegate, I could write different method to handle
functionality for different types of object. So, a search function could be
handled by a delegate and you could handle search for whatever kind of
object.
I say apriori because with .NET 2.0 we now have generics.

HTH
Steve
 
That is very interesting!

I am still having a bit of a problem conceptualizing where I might use this
outside of event trapping.

Thanks!
Ron
 
Back
Top