Ejemplo n.º 1
0
        public static void Main()
        {
            // Create an instance of the class that will be firing an event.
            FireAlarm myFireAlarm = new FireAlarm();

            // Create an instance of the class that will be handling the event. Note that
            // it receives the class that will fire the event as a parameter.
            FireHandlerClass myFireHandler = new FireHandlerClass(myFireAlarm);

            //use our class to raise a few events and watch them get handled
            myFireAlarm.ActivateFireAlarm("Kitchen", 3);
            myFireAlarm.ActivateFireAlarm("Study", 1);
            myFireAlarm.ActivateFireAlarm("Porch", 5);

            return;
        }
Ejemplo n.º 2
0
 // Create a FireAlarm to handle and raise the fire events.
 public FireHandlerClass(FireAlarm fireAlarm)
 {
     // Add a delegate containing the ExtinguishFire function to the class'
     // event so that when FireAlarm is raised, it will subsequently execute
     // ExtinguishFire.
     fireAlarm.FireEvent += new FireAlarm.FireEventHandler(ExtinguishFire);
 }