コード例 #1
0
        public static void Main()
        {
            //singlecast
            DelegateMethod sabiranje = new DelegateMethod(TwoNumAdd);

            Console.WriteLine(sabiranje(45, 50));

            RunDelegator(TwoNumAdd, 90, 50);
            RunDelegator(TwoNumMinus, 90, 50);

            Console.WriteLine("====================");

            //multicast
            DelegateMulticast del = new DelegateMulticast(TwoNumAdd2);

            del += new DelegateMulticast(TwoNumMinus2);

            del(100, 30);
            Console.WriteLine("====================");
            DelegateMethod delAnonymus = (int a, int b) => a * b;

            Console.WriteLine(delAnonymus(5, 10));

            Console.ReadKey();
        }
コード例 #2
0
        public static void run()
        {
            DelegateMulticast deleObj = new DelegateMulticast(Method_1);
            deleObj += new DelegateMulticast(Method_2);

            Console.WriteLine("Enter two values:");
            int v1 = Int32.Parse(Console.ReadLine());
            int v2 = Int32.Parse(Console.ReadLine());

            double result = deleObj(v1, v2);
            Console.WriteLine("Method_1 and Method_2 are called. Result={0}", result);

            deleObj -= new DelegateMulticast(Method_2);
            result = deleObj(v1, v2);
            Console.WriteLine("Only Method_1 called. Result={0}", result);

            Console.ReadKey();
        }