April 2002
Intermediate to advanced
1024 pages
23h 26m
English
delegates implement the ICloneable interface so that a delegate can be copied. The copy will be a deep copy so that each copy can exist independently, and changes to one will not affect changes in the other. Listing 14.19 shows a simple illustration. The full source for this code is in the DelegateClone directory.
DelegateCallback ad = new DelegateCallback(ACallback); DelegateCallback bd = new DelegateCallback(BCallback); DelegateCallback cd = new DelegateCallback(CCallback); DelegateCallback dd = ad; dd += bd; dd += cd; DelegateCallback ed = dd; Console.WriteLine("Original list"); Delegate [] da = dd.GetInvocationList(); foreach(Delegate d in da) { Console.WriteLine("{0} {1} ", d.Target, d.Method); ... |