Enabling Notifications with Events In the previous section, you saw how to declare a delegate type, call a delegate, and create delegate instances. However, this is only half the story. | Enabling Notifications with Events In the previous section you saw how to declare a delegate type call a delegate and create delegate instances. However this is only half the story. Although delegates allow you to invoke any number of methods indirectly you still have to invoke the delegate explicitly. In many cases it would be useful to have the delegate run automatically when something significant happens. For example in the automated factory scenario it could be vital to be able to invoke the stopMachinery delegate and halt the equipment if a machine overheats. In the .NET Framework events allow you to define and trap significant actions and arrange for a delegate to be called to handle the situation. Many classes in the .NET Framework expose events. Most of the controls that you can place on a Windows form and the Windows Form class itself use events to allow you to run code when for example the user clicks a button or types something in to a field. You can also define your own events. 1. Locate the method. Comment out the throw new Exception statement. The enumerator does not use any resources that require explicit disposal so this method does not need to do anything. It must still be present however. For more information about the Dispose method refer to Chapter 13. 2. Build the solution and fix any errors that are reported. Initializing a Variable Defined with a Type Parameter You should have noticed that the statement that defines and initializes the currentItem variable uses the default keyword. This keyword is a new feature in C . The currentItem variable is defined by using the type parameter T. When the program is written and compiled the actual type that will be substituted for T might not be known this issue is only resolved when the code is executed. This makes it difficult to specify how the variable should be initialized. The temptation would be to set it to null. However if the type substituted for T is a value type then .