Information Technology Reference
In-Depth Information
Declaring an Event
The publisher must provide the event and the code to raise the event.
Creating an event is simple—it requires only a delegate type and a name. The syntax for
an event declaration is shown in the following code, which declares an event called Elapsed .
Notice the following about event Elapsed :
It is declared inside a class called MyTimerClass .
￿
￿
It accepts event handlers with the return type and signature matching the delegate type
EventHandler .
￿
It is declared public so that other classes and structs can register event handlers with it.
class MyTimerClass
{ Keyword Name of event
public event EventHandler Elapsed;
Delegate type
You can declare more than one event in a declaration statement by using a comma-
separated list. For example, the following statement declares three events.
public event EventHandler MyEvent1, MyEvent2, OtherEvent ;
Three events
Events can also be static, by including the static keyword in the declaration, as shown in
the following code.
public static event EventHandler Elapsed;
Keyword
Search WWH ::




Custom Search