静态自定义方法:
static int counter = 0;
static string displayString = "This string will appear one letter at a time. ";
static void WriteChar(object source,ElapsedEventArgs a)
{
Console.Write(displayString[counter++%displayString.Length]);//此为关键逻辑处
}
主函数:
static void Main(string[] args)
{
Timer myTimer = new Timer(100);
myTimer.Elapsed += new ElapsedEventHandler(WriteChar);
myTimer.Start();
Console.ReadKey();
}
大家可以复制代码运行查看效果。
留下该例以后说不定会触类旁通。