+ 1

How do I get input of type int?

How do I get input of type int that works still if the input isn't an integer number? I tried like this but it doesn't work: https://code.sololearn.com/cOTzq7pAu1ZV/?ref=app I could put that Console.WriteLine inside the try-catch, but it doesn't work as well with multiple variables.

14th Jul 2018, 4:32 PM
Joel Kronqvist
Joel Kronqvist - avatar
2 Answers
+ 2
Joel I think Int.TryParse() will help you in this case. docs.microsoft.com has a good guide about it. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number
14th Jul 2018, 5:26 PM
ODLNT
ODLNT - avatar
+ 1
Thank you, this helped much. (and thanks to microsofts guide)
14th Jul 2018, 5:39 PM
Joel Kronqvist
Joel Kronqvist - avatar