![]() |
| multicast delegate |
MULTICAST DELEGATE
If we have
more than one method with same signature, here signature take as the same
return type and same parameter accepts. Than for those methods we use multicast
delegate to call all that method with one delegate name.
In this
topic we will discuss about three step to perform multicast delegate.
1. Defining the delegate
It is same like as delegate that’s
the delegate signature should match with method
signature except
name. The multi task will perform in creating instance part.
SYNTAX
[<
Modifier >] delegate <return type> Name (parameter list)
2. Instantiating the instance of multicast delegate
The main difference between delegate and
multicast delegate is going to declare here. We will create multiple method reference
by using one delegate name like this.
<Delegate
name> d.name = new <delegate name> (reference method)
This syntax can be return like this
<Delegate
name> d.name = <1st reference method>
d.name
+= <2nd reference method >
Here we use d.name for both methods and when
we give one time values theses method will execute by same value see the
example to clarify.
3. Calling the multicast delegate
It is also same like delegate calling. Calling
will do in two different ways.
1st way: <d.name>
(value1, value2… value n) //as
above mention d.name
2nd way: <d.name>.invoke (value1, value2… value n)
When we call one time all the linked method
will execute using same values.
Points to be noted while going to perform multicast
delegate
There some
points that should keep in mind when decide to make multicast delegate that’s
1. We use multicast delegate in such a time where multi method has
to execute by same values.
2. Before using of this delegate make sure that all your methods
are non-value returning type otherwise only the last method result will be shown
and rest all are overwrites by the last one. If your methods are value
returning type it better to use delegate instead of multicast delegate.





















