using System;
delegate void MyEventHandler();
class MyEvent {
public event MyEventHandler SomeEvent;
public void OnSomeEvent() {
if(SomeEvent != null)
SomeEvent();
}
}
class MainClass {
public static void Main() {
MyEvent evt = new MyEvent();
// Use an anonymous method as an event handler.
evt.SomeEvent += delegate {
// This is the event handler.
Console.WriteLine("Event received.");
};
evt.OnSomeEvent();
evt.OnSomeEvent();
}
}
|