Delegate(델리게이트) Example 1
using System;
using System.Collections.Generic;
using System.Text;
namespace DelegateExample
{
public class Calc
{
public static void Sum(int x, int y)
{
Console.WriteLine("{0} + {1} = {2}", x, y, (x + y));
}
public static void Mul(int x, int y)
{
Console.WriteLine("{0} * {1} = {2}", x, y, (x * y));
}
public static void Div(int x, int y)
{
Console.WriteLine("{0} / {1} = {2}", x, y, (x / y));
}
public static void Sub(int x, int y)
{
Console.WriteLine("{0} - {1} = {2}", x, y, (x - y));
}
}
public class MainClass
{
public delegate void CalDelegate(int a, int b);
public static void Main(string[] args)
{
CalDelegate caldelegate = new CalDelegate(Calc.Sum);
caldelegate += new CalDelegate(Calc.Sub);
caldelegate += new CalDelegate(Calc.Mul);
caldelegate += new CalDelegate(Calc.Div);
caldelegate(3, 5);
}
}
}
실행결과