question posted to me in an interview about Delegates.

What is a Delegate ?
A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value. Delegates can be used to define callback methods.Delegates can be chained together i.e. multiple methods can be called on a single event.

Explain the different types of Delegates?
There are two types of Delegates.The are as follows :
1. Single-cast delegate : A Single-cast delegate can call only one method at a time.A Single-cast Delegate is derived from the System.Delegate class. It contains reference to one method only at a time.
2. Multi-cast delegate : A Multi-cast delegate can call multiple methods at the same time.A multicast delegate is derived from the System.MulticastDelegate class. It contains an invocation list of multiple methods.The return type of all these delegates is same. A multicast delegate will execute all the methods it wraps in the calling order.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: