using System;
delegate int ArithOp(int x,int y);
class MathOperation
{
public static int Add(int a,int b)
{
return a+b;
}
static public int Sub(int a,int b)
{
return a-b;
}
}
class DelegateTest
{
static void Main()
{
ArithOp[] Op = { new ArithOp(MathOperation.Add),
new ArithOp(MathOperation.Sub)
};
for(int i=0;i<2;ProcessMethod(Op[i],200,100),i++);
Console.ReadKey();
}
static void ProcessMethod(ArithOp obj,int a,int b)
{
int result = obj(a,b);
Console.WriteLine("Result = "+result);
}
}
Output:-
No comments:
Post a Comment