Esempio n. 1
0
        static void Main(string[] args)
        {
            MyDivide myFunc = delegate(int a, int b)
            {
                if (b == 0)
                {
                    return(null);
                }

                return(a / b);
            };
            MyDivide2 myFunc2 = delegate(int a, int b)
            {
                if (b == 0)
                {
                    Console.WriteLine("{0}/{1} == {2}", a, b, null);
                }
                else
                {
                    Console.WriteLine("{0}/{1} == {2}", a, b, a / b);
                }
            };

            Console.WriteLine("------------Func delegete----------");
            Console.WriteLine("{0}/{1} == {2}", 10, 2, myFunc(10, 2));
            Console.WriteLine("{0}/{1} == {2}", 10, 0, myFunc(10, 0));
            Console.WriteLine("-----------Action Delegate---------");
            myFunc2(10, 2);
            myFunc2(10, 0);


            // 여기에 10 / 2 == 5     와 같이 출력되도록 write 문 완성할 것.
            // 여기에 10 / 0 ==        와 같이 출력되도록 write 문 완성할 것.
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            /* 1. 람다식으로 작성*/
            MyDivide myfunc = (a, b) =>
            {
                if (b == 0)
                {
                    return(a / 0);
                }

                return(a / b);
            };

            Console.WriteLine("{0} / {1} == {2}", 10, 2, myfunc(10, 2));
            Console.WriteLine("{0} / {1} == {2}", 10, 0, myfunc(10, 0));
            //MyDivide myFunc = delegate (int a, int b)
            //{
            //    if (b == 0)
            //    {
            //        return null;
            //    }

            //    return a / b;
            //};
            // 여기에 10 / 2 == 5     와 같이 출력되도록 write 문 완성할 것.
            // 여기에 10 / 0 ==        와 같이 출력되도록 write 문 완성할 것.
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            MyDivide myFunc = delegate(int a, int b)
            {
                if (b == 0)
                {
                    return(null);
                }
                return(a / b);
            };

            WriteLine("10/2 == " + myFunc(10, 2));
            WriteLine("10/2 == " + myFunc(10, 0));



            Console.WriteLine("Hello C#!");

            //Thread thread = new Thread(ThreadFunc);
            Thread thread = new Thread(
                delegate(object obj)
            {
                Console.WriteLine("ThreadFunc in anonymous method called!");
            });

            //Thread 타입의 생성자는 delegate 로 실행 함수를 전달 받는데 메서드 정의 대신
            //직접 delegate 예약어로 코드를 전달할 수도 이다. delegate 예약어 괄호 안에는 원래
            //delegate 형식에서 필요로 하는 매개변수를 전달해야 한다.

            thread.Start();

            thread.Join();
        }
Esempio n. 4
0
 void LambdaMethodTest()
 {
     MyDivide func = (a, b) =>
     {
         if (b == 0)
         {
             return(false, 0);
         }
Esempio n. 5
0
 //할때마다 델리게이트 만들어야되네
 private void AnynomousMethodTest()
 {
     MyDivide func = delegate(int a, int b)
     {
         if (b == 0)
         {
             return(false, 0);
         }
         return(true, a / b);
     };
 }
Esempio n. 6
0
        delegate(bool, int) MyDivide(int a, int b);     // 사용할 익명 메서드, 람다식에 대한 델리게이트 정의

        void AnonymousMethodTest()
        {
            MyDivide func = delegate(int a, int b)
            {
                if (b == 0)
                {
                    return(false, 0);
                }

                return(true, a / b);
            };

            Console.WriteLine(func(10, 5));
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            MyDivide myFunc = (a, b) =>
            {
                if (b == 0)
                {
                    return(null);
                }
                return(a / b);
            };

            Console.WriteLine("10 / 2 == " + myFunc(10, 2)); // 출력 결과: 10 / 2 == 5
            Console.WriteLine("10 / 0 == " + myFunc(10, 0)); // 출력 결과: 10 / 2 ==
        }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            MyDivide myFunc = delegate(int a, int b)
            {
                if (b == 0)
                {
                    return(null);
                }

                return(a / b);
            };

            Console.WriteLine("10 / 2 = " + myFunc(10, 2));
            Console.WriteLine("10 / 0 = " + myFunc(10, 0));
        }
Esempio n. 9
0
        private void oldLocalFuntion()
        {
            MyDivide func = delegate(int a, int b)  //델리게이트 방식
            {
                if (b == 0)
                {
                    return(false, 0);
                }
                return(true, a / b);

                ;
            };

            MyDivide func2 = (a, b) =>             //람다방식
            {
                if (b == 0)
                {
                    return(false, 0);
                }
Esempio n. 10
0
        private static void Main(string[] args)
        {
            MyDivide myFunc = (a, b) =>
            {
                if (b == 0)
                {
                    return(null);
                }

                return(a / b);
            };

            myFunc(10, 2);
            myFunc(10, 0);

            MyAdd myFunc0 = (a, b) => a + b;

            myFunc0(20, 30);
        }