델리게이트

개발 Programming/C#|2015. 4. 24. 13:54

using System;

using System.Collections.Generic;

using System.Text;


namespace ConsoleApplication1

{

    delegate int MyDelegate(int a, int b);


    class CalCulator

    {


        public int Plus(int a, int b)

        {

            return a + b;

        }

        public static int Minus(int a, int b)

        {

            return a - b;

        }

    }

    class MainApp

    {

        static void Main(string[] args)

        {

            CalCulator Calc = new CalCulator();

            MyDelegate CallBack;


            CallBack = new MyDelegate(Calc.Plus);

            Console.WriteLine(CallBack(3,4));


            CallBack = new MyDelegate(CalCulator.Minus);

            Console.WriteLine(CallBack(7,5));

        }

    }

}



소스를 참조로 전달해서 사용하기 위함



댓글()