Types of Delegates

By: Jesse Miller

There are types of delegates, Single-Cast delegate and Multicast delegate. A Single-cast delegate can call only one method at a time, whereas a Multicast delegate can call multiple methods at the same time.

A Single-cast derives from the System.Delegate class. It contains reference to one method only at a time. In the preceding example, the delegate used is a single-cast delegate. The WriteConsole () and WriteFile () methods are being referenced by the delegate, PrintData, one after the other, at runtime.

A multicast delegate derives from the System.MulticastDelegate class. It contains an invocation list of multiple methods. In multicasting a single delegate invokes multiple encapsulated methods. The return type of all these delegates is same.

Multicast delegates hold the reference of more than one method. A multicast delegate will execute all the methods it wraps in the calling order. The multiple methods called by the delegate in this case should not return any value because several multicast delegates are called consecutively and you cannot wait to get the return value from each of these methods.

Multicasting helps to call both the WriteFile () method and the WriteConsole () method in call.
The events are declared and raised in a class and associated with the event handlers using delegates within the same class or other classes. Events are part of a class and the same class is used to publish it events.

The other classes can, however, accept these events or in other words can subscribe to these events. Events use the publisher and subscriber model. A publisher is an object that contains the definition of the event and the delegate. The association of the event with the delegate is also specified in the publisher class.

The object of the publisher class invokes the event, which is notified to the other objects. A subscriber is an object that wants to accept the event and provide a handler to the event. The delegate of the publisher class invokes the method of he subscriber class.

This method in the subscriber class is the event handler. The publisher and subscriber model implementation can be defined by the same class. The implementation of an event includes events definition, events subscription and events notification.

Quick Note: Taking the Nonsense out of looking for the right spyware remover

If you really want to take the work out of looking for that right Spyware Protection from a go to the Internet and get a or a Free
Download, In order to prevent your vital information from being ripped from your computer get your Remover Today.

The definition of the event in a publisher class includes the declaration of the delegate as well as the declaration of the event based on the delegate. It associates with its handler.

Top Searches on
Computers
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Computers
 



Share this article :
Click to see more related articles