Exemple #1
0
        public static int CallDelegateReturn(int a)
        {
            status = a;
            DelegateReturn d = DelegateReturnTarget;

            return(d());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            MulticastDemo md   = new MulticastDemo();
            MathDelegate  dadd = new MathDelegate(MulticastDemo.Add);
            MathDelegate  dsub = new MathDelegate(MulticastDemo.Sub);
            MathDelegate  dmul = new MathDelegate(md.Mul);
            MathDelegate  ddiv = new MathDelegate(md.Div);
            // chaining all delegate
            MathDelegate rootd = dadd + dsub + dmul + ddiv;

            rootd = rootd - dsub - dmul - ddiv;
            rootd(12, 12);
            //  earlier path
            dsub(12, 10);
            dmul.Invoke(10, 10);

            // delegate return type
            DelegateReturn dr = new DelegateReturn(DelegateReturnDemo.MethodOne);

            dr = dr + DelegateReturnDemo.MethodTwo;
            int valueReturn = dr();

            Console.WriteLine($"Delegate Return for method Two: {DelegateReturnDemo.MethodOne()}");
            Console.WriteLine($"Delegate Return for method Two: {DelegateReturnDemo.MethodTwo()}");
            //  delegate out example
            DelegateOut delegateOut = new DelegateOut(DelegateOutDemo.MethodOne);

            delegateOut = delegateOut + DelegateOutDemo.MethodTwo;
            int returnOut = 0;

            delegateOut(out returnOut);
            Console.WriteLine($"Delegate OUT for method Two: { returnOut}");
            delegateOut -= DelegateOutDemo.MethodTwo;
            delegateOut(out returnOut);
            Console.WriteLine($"Delegate OUT for method One: { returnOut}");
        }