Delegates
Delegates are the pointers for the functions. The most amazing part of delegates is that you can point more than one function at a time and can call those functions from just one statement. The sequence of the function calling depends upon the sequence in which one adds the functions to the delegate.
Lets see an example.
using System;
namespace deligate
{
class Program
{public delegate int addDeligate(int a, int b);
static void Main(string[] args)
{
addDeligate d1 = new addDeligate(add);
Console.WriteLine(d1(3, 2));
Console.ReadLine();
}
public static int add(int a,int b)
{
return a + b;
}
}
}
Comments
Post a Comment