Make a Stopwatch C#

By sbondo1234 on 8 June, 2019

Step 1

Import System.Diagnostics:

using System.Diagnostics;

Step 2

Initialise the timer & start it:

Stopwatch timer = new Stopwatch();

Step 3

Stop the timer:


Step 4

Display stopwatch results:

Console.WriteLine(overallTimer.Elapsed.Seconds.ToString() + "s");

You can use a multiple amount of different timings such as:

  • Milliseconds
  • Minutes
  • Hours
  • Days

You can put ‘Total’ before the unit of timing to give the exact amount of time taken:

Console.WriteLine(overallTimer.Elapsed.TotalSeconds.ToString() + "s");