using System;
using System.Timers;
using System.Threading;
class MainClass
{
static void Main()
{
MyTimerClass mc = new MyTimerClass();
mc.Elapsed += delegate(object obj, EventArgs e){
Console.WriteLine("This is the anonymous method.");
};
Thread.Sleep(2000);
}
}
public class MyTimerClass
{
public event EventHandler Elapsed;
private void OnOneSecond(object obj, EventArgs e)
{
if (Elapsed != null)
Elapsed(obj, e);
}
private System.Timers.Timer MyPrivateTimer = new System.Timers.Timer();
public MyTimerClass()
{
MyPrivateTimer.Elapsed += OnOneSecond;
MyPrivateTimer.Interval = 1000;
MyPrivateTimer.Enabled = true;
}
}
This is the anonymous method.