How can I validate console input as integers?

You should test if it’s an int instead of converting in right away.
Try something like :

string line = Console.ReadLine();
int value;
if (int.TryParse(line, out value))
{
   // this is an int
   // do you minimum number check here
}
else
{
   // this is not an int
}

Leave a Comment