Delegaes concept using C# Language.
Jun 30, 2018
Delegates,
1014 Views
This Program is used to demonstrate the Delegates concept.
using System;
public class Operation
{
public static void Add(int a, int b)
{
Console.WriteLine("\nAddition={0}",a + b);
}
public static void Multiple(int a, int b)
{
Console.WriteLine("\nMultiply={0}", a * b);
}
}
public class exam
{
delegate void DelOp(int x, int y);
public static void Main()
{
// Delegate instantiation
DelOp[] obj = {new DelOp(Operation.Add),new DelOp(Operation.Multiple)};
for (int i = 0; i < obj.Length; i++)
{
obj[i](2,5);
obj[i](8,5);
obj[i](4,6);
}
}
}