用於將計時器設為零的 C# 程式
若要將計時器資訊設為零,請使用 Stopwatch Restart 方法。
首先,開始 Stopwatch −
Stopwatch s = Stopwatch.StartNew();
然後,使用 Restart() 將計時器設為零 −
s.Restart();
讓我們檢視完整程式碼 −
示例
using System; using System.Threading; using System.Diagnostics; public class Demo { public static void Main() { Stopwatch s = Stopwatch.StartNew(); Thread.Sleep(500); // restart s.Restart(); // begin again Thread.Sleep(500); Console.WriteLine(s.Elapsed); } }
輸出
00:00:00.5004937
廣告