A Simple Example of Delegates
using System;
public class Test
{
public delegate int CalculationHandler(int x, int y);
static void Main(string[] args)
{
Math math = new Math();
//create a new instance of the delegate class
CalculationHandler sumHandler = new CalculationHandler(math.Sum);
//invoke the delegate
int result = sumHandler(8,9);
Console.WriteLine("Result is: " + result);
}
}
public class Math
{
public int Sum(int x, int y)
{
return x + y;
}
}
No comments:
Post a Comment