// The method to handle temperature change events.
 public void TemperatureChange(Object sender,
                               TemperatureChangedEventArgs temp)
 {
     Console.WriteLine("ChangeObserver: Old={0}, New={1}, Change={2}",
                       temp.OldTemperature, temp.NewTemperature,
                       temp.NewTemperature - temp.OldTemperature);
 }
        // The method to handle temperature change events.
        public void TemperatureChange(Object sender,
                                      TemperatureChangedEventArgs temp)
        {
            count++;
            sum += temp.NewTemperature;

            Console.WriteLine
                ("AverageObserver: Average={0:F}", (double)sum / (double)count);
        }
 // A protected method used to raise the TemperatureChanged event.
 // Because events can be triggered only from within the containing
 // type, using a protected method to raise the event allows derived
 // classes to provide customized behavior and still be able to raise
 // the base class event.
 virtual protected void OnTemperatureChanged
     (TemperatureChangedEventArgs args)
 {
     // Notify all observers. A test for null indicates whether any
     // observers are registered.
     if (TemperatureChanged != null)
     {
         TemperatureChanged(this, args);
     }
 }