Information Technology Reference
In-Depth Information
Invoking a Delegate
You invoke a delegate by calling it, as if it were simply a method. The parameters used to invoke
the delegate are used to invoke each of the methods on the invocation list (unless one of the
parameters is an output parameter, which I will explain shortly).
For example, the delegate delVar , as shown in the following code, takes a single integer
input value. Invoking the delegate with a parameter causes it to invoke each of the members in
its invocation list with the same parameter value (55, in this case). The invocation is illustrated
in Figure 15-8.
MyDel delVar = Inst.MyM1;
delVar += SCl.m3;
delVar += X.Act;
...
delVar( 55 ); // Invoke the delegate.
...
Figure 15-8. When the delegate is invoked, it invokes each of the methods in its invocation list,
with the same parameters with which it was called.
A method can be in the invocation list more than once. If that is the case, then when the
delegate is invoked, the method will be called each time it is encountered in the list.
Search WWH ::




Custom Search