Events are essential entities for Web programming. They are functions that are used to report user interaction with Web forms and Web controls, among other objects. Events are built on top of delegates, so to declare an event in C# you first declare a delegate. The event declaration then tells the compiler to add a field of the delegate type and two functions: add and remove. The delegate field maintains a list of delegates by combining and removing delegates from the field. The add and remove functions enable classes to subscribe and unsubscribe from the list of delegates. By firing the event, the class invokes a method on all of the subscribers in the list. To declare an event:
To fire the event:
Tips
|