Learn to Code via Tutorials on Repl.it!

← Back to all posts
How to make a stopwatch in c#

Today you will learn to make a stopwatch in pure c#, nothing else

Start by adding

that is all the using statements you need, next create a Stopwatch by doing this

name it anything you want
then prompt the user to press a key and then clear it by doing this

then do this

then when the user presses another key

then this is the hard part, create a TimeSpan

then do this code

if you want hours as well do this

the string.format is how the elapsed time will be displayed when you actually run it
I hope this was helped and you enjoyed, so now bye