C# Program to set the timer to zero

CsharpProgrammingServer Side Programming

To set the timer information to zero, use the Stopwatch Restart method.

Firstly, begin the Stopwatch −

Stopwatch s = Stopwatch.StartNew();

Then, use Restart() to set the timer to zero −

s.Restart();

Let us see the complete code −

Example

Live Demo

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);
   }
}

Output

00:00:00.5004937
raja
Updated on 22-Jun-2020 14:18:51

Advertisements