|
.NET delegates and events - August 25, 2008 at 18:00 PM by
Amit Satpute
What is an Event?
Answer
When an action is performed, this action is noticed by the computer
application based on which the output is displayed. These actions are called
events. Examples of events are pressing of the keys on the keyboard, clicking
of the mouse. Likewise, there are a number of events which capture your
actions.
Define Delegate.
Answer
Delegates are kind of similar to the function pointers. But they are
secure and type-safe.
A delegate instance encapsulates a static or an instance method.
Declaring a delegate defines a reference type which can be used to encapsulate
a method having a specific signature.
What is the purpose of AddHandler keyword?
Answer
The AddHandler statement allows you to specify an event handler. AddHandler has
to be used to handle shared events or events from a structure.
The arguments passed to the Addhandler are:
The name of an event from an event sender and
An expression that evaluates to a delegate
|