What is Multicast Delegate? Explain it with example in C#?Delegates
are used to wrap and execute methods having the same signature as that
of the delegate. They wrap method calls and prevent exposing the actual
method name to the User.
Delegates have a very special feature which supports execution of multiple methods using a single delegate call. This is known as multicast delegate. For a delegate you can define an invocation list and while calling the delegate, all the methods in its invocation list will be executed. You can add methods to the invocation list using += operator. You can also remove methods from the list using -= operator. The following example demonstrates usage of multicast delegate in C# by creating a delegate and executing two different methods using the same delegate: public delegate
void sampleDelegate(int data); Output of this code will be: This number
is an even number
|