Multicasting is an excellent feature of delegates. With multicasting, you can assign more than one method to a delegate. When that delegate is executed, it runs all the methods that were assigned one after another. Using the + or += operator, you can add methods to a delegate. There is also a way to remove added methods from the delegate. To do this, you have to use the - or -= operator. Let's look at an example to understand clearly what multicasting is:
using System;
namespace MyDelegate
{
delegate void MathFunc(ref int a);
class Program
{
static void Main(string[] args)
{
MathFunc mf;
int number = 10;
MathFunc myAdd = MyMath.add5;
MathFunc mySub = MyMath.sub3;
mf = myAdd;
mf += mySub;
mf(ref number);
Console.WriteLine($"Final number: {number}");
Console.ReadKey();
}
}
class MyMath
{
public...