What are some common scenarios where we should implement delegates

T

trubar a

hi

I understand how delegates and events work. I can also imagine some
common scenarios where we should implement events, but I’m having
harder times understanding in what situations should we implement
delegates (not events).

thanx
 
V

vanderghast

When you need a custom process. As example, List<T>.TrueForAll(
Predicate<T> ) Note that Predicate is a specific delegate, it is a
delegate which returns a Boolean. In this case, the 'delegate' will say WHAT
you mean exactly by an element being "tested" and to return true, or false.
Same with the generic method List"<T>.Find( Predicate<T> ), the delegate may
be use to define a more or less complex condition stating if a given object
(class T) can be consider a match, or not.

A little bit the same thing if you want to order objects among themselves:
will they be order by their last name, first name, the registered
date_time, ... You can supply, for the comparison, what you intend, in your
specific case, to be greater, equal, or smaller, to a method having defined
the general method (to sort), but which is missing this specific method to
complete its task.

Another example would be supplying a mathematical package to find the area
under a curve. The curve would probably be supplied as a delegate to your
method finding the area.


Vanderghast, Access MVP

hi

I understand how delegates and events work. I can also imagine some
common scenarios where we should implement events, but I’m having
harder times understanding in what situations should we implement
delegates (not events).

thanx
 
O

ozbear

hi

I understand how delegates and events work. I can also imagine some
common scenarios where we should implement events, but I=92m having
harder times understanding in what situations should we implement
delegates (not events).

thanx

If you are familiar with other languages, delegates are function
pointers, only made type-safe.

Oz
 

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