C# 程序计时 其他 2021-03-05 23:04 0 阅读 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(); 猜你喜欢