Esempio n. 1
0
        // Declare a delegate

        public void NamedMethod()
        {
            DelegateSamples m = new DelegateSamples();

            // Delegate instantiation using "Multiply"
            MathDelegate d = m.Multiply;

            // Invoke the delegate object.
            Console.WriteLine("Invoking the delegate using 'Multiply':");
            for (int i = 1; i <= 5; i++)
            {
                d(i, 5);
            }
            Console.WriteLine("");
        }
        static void Main(string[] args)
        {
            DelegateSamples c5s = new DelegateSamples();

            c5s.NamedMethod();
            c5s.InvokeDelegate();
            c5s.InvokeDelegatebyAnonymousFunction();
            c5s.LambdaOperatorExample();
            c5s.CoVarianceSample();
            c5s.ContraVarianceSample();
            c5s.MulticastDelegate();


            EventSamples e5s = new EventSamples();

            e5s.Run();
            // Keep the console window open in debug mode.
            System.Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();
        }