Beruflich Dokumente
Kultur Dokumente
Delegate (Contd.)
Using Delegate
{
//Initializing the Delegate object
PrintData Cn = new PrintData (WriteConsole);
PrintData Fl = new PrintData (WriteFile);
//Invoking the DisplayData method with the
Delegate object as the argument
//Using Delegate
DisplayData (Cn);
DisplayData (Fl);
Console.ReadLine();
}
}
}
Types of Delegates
Delegates are of two types and depending upon the
requirement of the application the suitable type of delegate
is selected.
Single-Cast Delegate
A single-cast delegate derives from the System.Delegate
class.
It contains reference to one method only at a time.
Multicast Delegate
A multicast delegate derives from the
System.MulticastDelegate class.
It contains an invocation list of multiple methods. In
multicasting you create a single delegate that invokes
multiple encapsulated methods.
Multicast delegates hold the reference of more than one
method therefore, if you call a multicast delegate it will
executes all the methods it wraps in the calling order.
The multiple methods called by the delegate in this case
should not return any value. Several multicast delegates are
called consecutively and you cannot wait to get the return
value from each of these methods.
Just a minute
State whether the following statement is True or False.
Multicast delegates inherit from the
System.Delegate.MulticastDelegate class.
Answer:
False