Esempio n. 1
0
        static void RemoveTargets()
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("=> Removing Targets from a Delegate's Invocation List");

            Car c1 = new Car("SlugBug", 100, 10);

            c1.RegisterWithCarEngine(new Car.CarEngineHandler(OnCarEngineEvent));

            Car.CarEngineHandler handler2 = new Car.CarEngineHandler(OnCarEngineEvent2);
            c1.RegisterWithCarEngine(handler2);
            Console.WriteLine("===== Speeding up =====");
            for (int i = 0; i < 7; i++)
            {
                c1.Accelerate(20);
            }

            c1.UnRegisterWithCarEngine(handler2);
            c1.Speed = 10;
            c1.StatusReset();
            Console.WriteLine("----- Speeding up -----");
            for (int i = 0; i < 7; i++)
            {
                c1.Accelerate(20);
            }
        }