I'm trying to make a simple stopwatch for a C# class I'm taking. I've googled around all afternoon and found a lot of info that I either don't understand or doesn't quite deal with the problem I'm having.
As I'm currently learning about classes, methods, fields and properties, I'm trying to design my stopwatch like this:
I don't think it needs to be super precise. I'm trying to get a DateTime.now object at the moment a key is pressed on the keyboard:
DateTime.now start = Console.ReadKey();
I've also tried:
var start = DateTime.now(Console.ReadKey());
That doesn't work either.
I've looked at the documentation for the StopWatch class in C#, but that seems way too advanced for me. I've read the page like 3 times and still don't have clue what it does: MS StopWatch class doc
I hope someone here can help me out a bit. best regards, Jacob Collstrup
What you want is something like this:
The call to
Console.ReadKey()
will block until a key has been pressed. Once that line has returned then you get the current time.Same for the stop time.