Delegate :
Delegate is a type which holds the method(s) reference in an object. It is also referred to as a type safe function pointer.
delegate void Delegate_Multicast(int x, int y);
Class Class2
{
static void Method1(int x, int y)
{
Console.WriteLine("You r in Method 1"); }
static void Method2(int x, int y)
{
Console.WriteLine("You r in Method 2");
}
public static void Main()
{
Delegate_Multicast func = new Delegate_Multicast(Method1);
func += new Delegate_Multicast(Method2);
func(1,2); // Method1 and Method2 are called
func -= new Delegate_Multicast(Method1);
func(2,3); // Only Method2 is called
}
00:40 |
Category:
C# Concepts
|
0
comments
Comments (0)