【C#-程序时间计数器】如何计算某些步骤/过程耗时多少?

使用Stopwatch对象,TimeSpan对象

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

 

posted @ 2016-08-24 15:27  发明创造小能手  阅读(240)  评论(0编辑  收藏  举报
levels of contents