I'm trying to validate if the 'columnsValidation' is a numeric string, and convert it to an int, if so.
For some reason, I end up in an endless loop, because 'isNumber' always equals false...
This code is part of my lottery project.
I hope that my question is clear enough, if additional information is needed just tell me and I'll answer.
Thanks in advance, Ilan.
Console.WriteLine("Please insert the number of rows: ");
string columnsValidation = Console.ReadLine();
bool isNumber = false;
while(isNumber == false)
{
bool.TryParse(columnsValidation, out isNumber);
if (isNumber == true)
columns = int.Parse(columnsValidation);
else
{
Console.WriteLine("You've inserted an invalid value, please try again.");
columnsValidation = Console.ReadLine();
}
}
trueas input...bool.TryParseis incorrect. If you aren't going to use it's output, then you might as well usebool.Parse(columnsValidation)