using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calsi_delegate
{
public delegate void method(int a, int b);
class Program
{
public static void add(int a, int b)
{
int c = a + b;
Console.WriteLine(c);
}
public static void mul(int a, int b)
{
int c = a * b;
Console.WriteLine(c);
}
public static void div(int a, int b)
{
try
{
int c = a / b;
Console.WriteLine(c);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter value of first number");
int f = int.Parse(Console.ReadLine());
Console.WriteLine("Enter value of second number");
int s = int.Parse(Console.ReadLine());
method m = new method(add);
m(f, s);
m -= new method(add);
m += new method(Program.mul);
m(f, s);
m -= new method(mul);
m += new method(Program.div);
m(f, s);
// or
//method m = new method(add);
//m += new method(Program.mul);
//m += new method(Program.div);
//m(f, s);
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calsi_delegate
{
public delegate void method(int a, int b);
class Program
{
public static void add(int a, int b)
{
int c = a + b;
Console.WriteLine(c);
}
public static void mul(int a, int b)
{
int c = a * b;
Console.WriteLine(c);
}
public static void div(int a, int b)
{
try
{
int c = a / b;
Console.WriteLine(c);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter value of first number");
int f = int.Parse(Console.ReadLine());
Console.WriteLine("Enter value of second number");
int s = int.Parse(Console.ReadLine());
method m = new method(add);
m(f, s);
m -= new method(add);
m += new method(Program.mul);
m(f, s);
m -= new method(mul);
m += new method(Program.div);
m(f, s);
// or
//method m = new method(add);
//m += new method(Program.mul);
//m += new method(Program.div);
//m(f, s);
Console.ReadKey();
}
}
}
// This program is created by Jaspreet Singh
0 comments:
Post a Comment