Beispiel #1
0
        static void Main(string[] args)
        {
            NumberFunction func = Square;

            Console.WriteLine("result of delegate is: {0}", func(5));
            func = Cube;
            Console.WriteLine("result of delegate is: {0}", func(5));
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            NumberFunction f = Square;

            Console.WriteLine("Result of the delegate is {0}", f(5));

            f = Cube;
            Console.WriteLine("Result of the delegate is {0}", f(5));

            Console.ReadLine();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            int            x = 2;
            NumberFunction f = Square;

            Console.WriteLine(f(x));

            // now you are changing the delegate on the fly
            // while the program is running you are changing what the delegate (the method) is doing
            f = Cube;
            Console.WriteLine(f(x));

            Console.Read();
        }