C#

C# / 대리자 실습 - Delegate / 덧셈 뺄셈을 위한 대리자

universedevelope 2022. 8. 10. 15:01
class Program
    {
        static void Main(string[] args)
        {
            int Plus(int a, int b)
            {
                return a + b;
            }

            int Minus(int a, int b)
            {
                return a - b;
            }

            // DeleGate 실습
            MyDeleGate CallBack;

            CallBack = new MyDeleGate(Plus);
            Console.WriteLine(CallBack(3, 4));  // 7

            CallBack = new MyDeleGate(Minus);   
            Console.WriteLine(CallBack(4, 1));  // 3


            
        }

        delegate int MyDeleGate(int a, int b);

        

        
    }
728x90