C# - Events & Indexers

In C# events are a special type of delegate. An event member of a class provides notifications from user or machine input.

A class defines an event by providing an event declaration, which is of type delegate. The following line shows the definition of an event handler:

public delegate void EventHandler(object sender, System.EventArgs e);

The EventHandler takes two arguments: one of type object and the other of type System.EvenArgs. A class implements the event handler using the event keyword.

Windows is an event- driven operating system. In Windows programming, the system sends messages to the massage queue for every action taken

by a user or the system, such as mouse–click, keyboard, touch screen, and timers. Even if the operating system is doing nothing, it still sends an idle message to the message queue after a certain interval of time. Although you usually use events in GUI applications, you can also implement events in

console-based application. You can use them when you need to notify a state of an action.

Indexers are a new concept in C#. Indexers enable a class object to function as an array. Implementing indexers is similar to implementing properties using the get and set functions. The only different is that when you call an indexer, you pass an indexing parameter. Accessing an indexer is similar to accessing an array. Indexers are nameless, so the this keyword declares indexers.