18.2. Multicasting

So far we have seen that delegates encapsulate a single function call. However, a delegate can also refer to multiple functions. Just as an object method call can encapsulate multiple method calls within it, a delegate can actually call multiple functions.

You can use the operators “+” and “-” to add and remove delegates. Whenever a delegate points to multiple functions, all the functions get called in the order in which they are added to the invocation list. The invocation list is a CLR-maintained list of functions of a delegate that need to get called.

Listing 18.4 shows a delegate pointing to multiple function calls.

Listing 18.4. Adding Delegates (C#)
 using System; public class Test { public delegate float CalcIncome(float ...

Get .NET for Java Developers: Migrating to C# 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.