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 aDelegate = new Math.DelegateToMethod(math.Add);
Math.DelegateToMethod mDelegate = new Math.DelegateToMethod(math.Multiply);
Math.DelegateToMethod dDelegate = new Math.DelegateToMethod(math.Divide);
aDelegate(5, 5);
mDelegate(5, 5);
dDelegate(5, 5);
Console.ReadLine();
}
}
}