You have a simple console application in which the user is prompted to enter several values. The input is read through console.readline (). Ex
Name: Fred
Lastname: Ashcloud
Age: 28
I would like to make sure that int and double types are entered, and if the user enters the garbage, allows him to repeat the procedure.
For example, if a user enters “28 years old,” where age expects the application to crash. What is the best way to test these inputs?
Now I can only think:
while (!Int32.TryParse(text, out number))
{
Console.WriteLine("Error write only numbers");
text = Console.ReadLine();
}
Is there any other way to do this? try to catch statements if you want to give more detailed feedback to the user? How in this case?
Milan source
share