public static string stopwatch()
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
String elapsedTime = String.Format("{0:0}.{1:000}", ts.Seconds, ts.Milliseconds / 1000);
return elapsedTime;
}
static void Main(string[] args)
{
string elptime = stopwatch();
for (Console.ReadKey(true); ;)
{
Console.WriteLine(elptime);
}
}
}
So I want to make a program that will each time i press button write in console value from Stopwatch();
with this order, for example:
0.520
0.801
1.255
But instead of this it comes down to:
0.000
0.000
0.000
0.000
0.000
Like infinite array
stopwatch
starts a new stopwatch instance you should reuse it.stopwatch
multiple times...Stopwatch
instance again.