C# 程序计时

C# 程序计时


string str = null;
//创建了一个计时器,用来记录程序运行的时间
Stopwatch sw = new Stopwatch();

sw.Start();//开始计时
for (int i = 0; i < 100000; i++)
{
    
    
	str += i;
}
sw.Stop();//结束计时
//打印时间
Console.WriteLine(sw.Elapsed);//sw.Elapsed并不是字符串类型,可以通过ToString()转换
Console.ReadKey();

猜你喜欢

转载自blog.csdn.net/qq_38463737/article/details/113512821