用於將計時器設為零的 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

更新日期: 2020 年 6 月 22 日

392 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告