54.multicasting delegate in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace multicasting_delegate
{
public delegate void Delegate_op(double a, double b);
class Program
{
static void mul(double x, double y)
{
Console.WriteLine("Multiplication : " + x * y);
}
static void add(double x, double y)
{
Console.WriteLine("Addition : " + (x + y));
}
static void div(double x, double y)
{
Console.WriteLine("Division : " + x / y);
}
static void sub(double x, double y)
{
Console.WriteLine("Substraction : " + (x - y));
}
static void Main(string[] args)
{
Delegate_op obj = new Delegate_op(mul);
obj += new Delegate_op(add);
obj += new Delegate_op(sub);
obj += new Delegate_op(div);
obj(10, 22);
Console.WriteLine("==============================");
obj -= new Delegate_op(add);
obj -= new Delegate_op(div);
obj(10, 22);
Console.Read();
}
}
}
Comments
Post a Comment