If you have a delegate instance, it will have zero or more methods in its invocation list. When you invoke the delegate instance, these are the methods that will be called.
For a given delegate instance, you can add or remove methods to its invocation list. In actuality, since a delegate is immutable, you’re actually creating a new delegate instance that has the specified methods added or removed.
Below are several examples of how you might add a new method to the invocation list of an existing delegate instance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Add Method2 to original invocation list StringHandlerDelegate del1 = Method1; del1 += Method2; del1( "Howdy 1" ); // Does the same thing del1 = Method1; del1 = del1 + Method2; del1( "Howdy 2" ); // Does the same thing del1 = Method1; del1 = (StringHandlerDelegate)Delegate.Combine(del1, new StringHandlerDelegate(Method2)); del1( "Howdy 3" ); |