使用Stopwatch对象,TimeSpan对象
Stopwatch sw = new Stopwatch();//跑表,该类可以进行时间的统计 命名空间using System.Diagnostics; sw.Start(); //跑表开始//花费时间的目标 sw.Stop(); //跑表结束 TimeSpan ts = sw.Elapsed; //统计到的时间 Console.WriteLine(ts.Milliseconds); //输出统计到的时间的毫秒数