using System; namespace Test { public delegate int BinaryOp(int x, int y); public class MyMath { public static int Add(int x, int y) { return x + y; } public static int Sub( int x, int y ) { return x - y; } public static int mul( int x, int y ) { return x * y; } public static int div(int x, int y) { int one = x; int two = y; int sum = 0; try { sum = one / two; } catch( Exception ) { Console.WriteLine( "You try to divide by 0 which is impossible." ); } return sum; } } public class Program { public static int Main() { BinaryOp bo = new BinaryOp(MyMath.Add); BinaryOp bo1 = new BinaryOp(MyMath.div); BinaryOp bo2 = new BinaryOp(MyMath.mul); BinaryOp bo3 = new BinaryOp(MyMath.Sub); Console.WriteLine( "Sum of MyMath.Add = {0}", bo( 5, 5 ) ); Console.WriteLine( "Sum of MyMath.Div = {0}", bo1( 5, 0 ) ); Console.WriteLine( "Sum of MyMath.Mul = {0}", bo2( 5, 3 ) ); Console.WriteLine( "Sum of MyMath.Sub = {0}", bo3( 5, 3 ) ); return 0; } } }