I have the following code:
aVariable = int.Parse(Console.ReadLine());
One problem I have is I cannot find any support material to help validate the user input, for instance if the user pressed the letter a, this would simply kill the program.
What can I do? Where can I find a decent tutorial?
Rather than using the Parse method use TryParse instead.
int age;
bool isValidInt = int.TryParse(Console.ReadLine(), out age);
You can use TryParse for this.. just google for this method. Or you can catch for exceptions to prevent your program to crash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With