Information Technology Reference
In-Depth Information
Assigning Delegates
Because delegates are reference types, you can change the reference contained in a delegate vari-
able, by assigning to it. The old delegate object is disposed of by the Garbage Collector (GC).
For example, the following code sets and then changes the value of delVar . Figure 15-4
illustrates the code.
MyDel delVar;
delVar = MyInstObj.MyM1; // Create and assign the delegate object.
...
delVar = SClass.OtherM2; // Create and assign the new delegate object.
Figure 15-4. Assigning to a delegate variable
Search WWH ::




Custom Search