using System;
namespace Delegates
{
public class Math
{
// note that the delegate now is a nested type of the Math class
public delegate void DelegateToMethod(int x, int y);
public void Add(int first, int second)
{
Console.WriteLine("The method Add() returns {0}", first + second);
}
public void Multiply(int first, int second)
{
Console.WriteLine("The method Multiply() returns {0}", first * second);
}
public void Divide(int first, int second)
{
Console.WriteLine("The method Divide() returns {0}", first / second);
}
}
public class DelegateApp
{
public static void Main()
{
Math math = new Math();
Math.DelegateToMethod multiDelegate = null;
multiDelegate = new Math.DelegateToMethod(math.Add);
multiDelegate += new Math.DelegateToMethod(math.Multiply);
multiDelegate += new Math.DelegateToMethod(math.Divide);
multiDelegate(10, 10);
Console.ReadLine();
}
}
}