Hello! I am a newbie programmer and I've been trying to deal with this problem for over 2 hours now. What I want the program to do is count seconds and if it gets past the third second, to do something, for example to show "Game Over" or something like that.
//...
TimeSpan ts = TimeSpan.FromSeconds(2);
int time = Convert.ToInt32(ts);
var keyPress = Console.ReadKey();
string keyPressString = keyPress.KeyChar.ToString();
keyPressString = keyPressString.ToUpper();
//...
else if (keyPressString != lettersAndChars && time > 3)
{
Console.WriteLine("Game Over");
}
First I tried Stopwatch, now I tried TimeSpan, but in both cases it shows me this exception: Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.
How do I fix it ? Thanks in advance!
Go to the complete details ...