Ejemplo n.º 1
0
        static void Main(string[] args) {
           
            Car c1 = new Car("SlugBug", 100, 10);

            c1.AboutToBlow += (sender, e) => { Console.WriteLine("Eek!, Going too fast!"); };
            c1.AboutToBlow += (sender, e) => { Console.WriteLine("Message from Car {0}", e.msg); };        
            c1.Exploded += (sender, e) => { Console.WriteLine("Message from Car {0}", e.msg); };


            for (int i = 0; i < 6; i++) {
                c1.Accelerate(20);
            }

           

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** More Fun with Lambdas *****\n");

            // Make a car as usual.
            Car c1 = new Car("SlugBug", 100, 10);

            // Now with lambdas!
            c1.AboutToBlow += (sender, e) => { Console.WriteLine(e.msg); };
            c1.Exploded += (sender, e) => { Console.WriteLine(e.msg); };

            // Speed up (this will generate the events).
            Console.WriteLine("\n***** Speeding up *****");
            for (int i = 0; i < 6; i++)
                c1.Accelerate(20);

            Console.ReadLine();
        }