public Example_multicasting_delegate2() { Console.WriteLine("***** Delegates as event enablers *****\n"); // First, make a Car object. Car2 c1 = new Car2("SlugBug", 100, 10); // Versi lain registrasi handler // Register event handlers. c1.AboutToBlow += new Car2.CarEngineHandler(CarIsAlmostDoomed); c1.AboutToBlow += new Car2.CarEngineHandler(CarAboutToBlow); Car2.CarEngineHandler d = new Car2.CarEngineHandler(CarExploded); c1.Exploded += d; Console.WriteLine("***** Speeding up *****"); for (int i = 0; i < 6; i++) { c1.Accelerate(20); } // Remove CarExploded method // from invocation list. c1.Exploded -= d; Console.WriteLine("\n***** Speeding up *****"); for (int i = 0; i < 6; i++) { c1.Accelerate(20); } Console.ReadLine(); }
public Example_multicasting_delegate2() { Console.WriteLine("***** Delegates as event enablers *****\n"); // First, make a Car object. Car2 c1 = new Car2("SlugBug", 100, 10); // Versi lain registrasi handler // Register event handlers. c1.AboutToBlow += new Car2.CarEngineHandler(CarIsAlmostDoomed); c1.AboutToBlow += new Car2.CarEngineHandler(CarAboutToBlow); Car2.CarEngineHandler d = new Car2.CarEngineHandler(CarExploded); c1.Exploded += d; Console.WriteLine("***** Speeding up *****"); for (int i = 0; i < 6; i++) c1.Accelerate(20); // Remove CarExploded method // from invocation list. c1.Exploded -= d; Console.WriteLine("\n***** Speeding up *****"); for (int i = 0; i < 6; i++) c1.Accelerate(20); Console.ReadLine(); }