Professional Documents
Culture Documents
Delegates and Events Programs
Delegates and Events Programs
class Program
{
public delegate void addnum(int a, int b);
public delegate void subnum(int a, int b);
del1(a, b);
del2(a, b);
Console.ReadKey();
}
}
Example:
namespace delegatesandeventsexample2
{
// Delegate Definition
public delegate int operation(int x, int y);
class Program
{
// Method that is passes as an Argument
// It has same signature as Delegates
static int Addition(int a, int b)
{
return a + b;
}
// output
Console.WriteLine("Addition is={0}", obj(23, 27));
Console.ReadLine();
}
}
}
Example:
class Program
{
// Delegate Definition
delegate void operation();
Console.ReadLine();
}
}
Example:
Console.ReadLine();
}
}
Example:
namespace delegatesandeventsexample7
{
public delegate void DelEventHandler();
class Program
{
public static event DelEventHandler add;
Console.ReadLine();
}
static void USA()
{
Console.WriteLine("USA");
}
class Program
{
static int a = 35, b = 12, c;
public static event DelEventHandler calc;
Console.ReadLine();
}
static void addition()
{
Console.WriteLine("Addition = "+(Program.a+Program.b));
}