Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Delegates as event enablers *****\n");
            Car c1 = new Car("Slug Bug", 100, 10);

            c1.RegisterWithCarEngine(new Car.CarEventHandler(OnCarEngineEvent));
            Car.CarEventHandler handler2 = new Car.CarEventHandler(OnCarEngineEvent2);
            c1.RegisterWithCarEngine(handler2);
            Console.WriteLine("***** Speeding Up *****");

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

            Console.WriteLine("\n");

            c1.UnregisterWithCarEngine(handler2);
            
            c1.ResetCar();
            c1.CurrentSpeed = 10;
            
            Console.WriteLine("***** Speeding Up *****");
            for (int i = 0; i < 6; i++)
                c1.Accelerate(20);

            Console.ReadLine();

        }