示例#1
0
    public static void Main(string[] args)
    {
        // Here is the Code that uses the delegate defined above.
        SampleDelegate sd = new SampleDelegate(CallMeUsingDelegate);

        sd.Invoke("FromMain");
    }
示例#2
0
        static void Main(string[] args)
        {
            //Rectange();
            program p = new program();

            #region MathDelegate
            //MathDelegate del1 = new MathDelegate(Add);
            //MathDelegate del2 = new MathDelegate(program.Sub);
            //MathDelegate del3 = p.Mul;
            //MathDelegate del4 = new MathDelegate(p.Div);

            //MathDelegate del5 = del1 + del2 + del3 + del4;

            //del5.Invoke(20, 5);
            //Console.WriteLine();

            //del5 -= del3;

            //del5(22, 7);
            #endregion

            SampleDelegate sampleDelegate = new SampleDelegate(MethodOne);
            sampleDelegate += MethodTwo;

            int ValueReturnedByDelegate = sampleDelegate.Invoke(2);

            Console.WriteLine($"Returned Value is {ValueReturnedByDelegate}");

            Console.ReadKey();
        }
示例#3
0
    public static void Main(string[] args)
    {
        // Here is the Code that uses the delegate defined above.
        SampleDelegate sd = delegate(param) {
            Console.WriteLine("Called me using parameter - " + param);
        };

        sd.Invoke("FromMain");
    }
        /// <summary>
        ///     処理を実行します。
        /// </summary>
        public void Execute()
        {
            //
            // 匿名メソッドを構築して実行.
            //
            SampleDelegate d = delegate { Output.WriteLine("SAMPLE_ANONYMOUS_DELEGATE."); };

            d.Invoke();
        }
示例#5
0
        static void Main(string[] args)
        {
            AnotherClass    ac = new AnotherClass();
            DelegateExample de = new DelegateExample();
            SampleDelegate  sd = new SampleDelegate(ac.Method1);

            sd += de.DellMethod;
            sd.Invoke();
            Console.ReadLine();
        }