Information Technology Reference
In-Depth Information
Adding Anonymous Method Event Handlers
You can also add anonymous method event handlers, just as with delegates.
For example, the following code adds an anonymous method to the event and then sleeps
for a little more than 2 seconds. The event is raised twice in that time.
Anonymous method
mc.Elapsed += delegate(object obj, EventArgs e)
{
Console.WriteLine("This is the anonymous method.");
};
Semicolon required
Thread.Sleep(2250);
}
This code produces the following output:
This is the anonymous method.
This is the anonymous method.
Search WWH ::




Custom Search