14.3. Combining delegates

If each delegate instance is only good for encapsulating one method, then its use will be very limited. The good news is that you can have one delegate instance encapsulating multiple methods in its invocation list. [6] It does not matter whether the methods in a delegate instance's invocation list are static or not. It also does not matter if these methods are totally unrelated and belong to classes in unrelated namespaces. All that matters is that each method matches the delegate type's return type and parameters.

[6] Some books use the terms 'composite delegate' or 'multi-cast delegate' to refer to delegate instances with more than one method in their invocation list.

You can use the + and - operators (as well as += ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.