C#C
C#2y ago
Steadhaven

Do while with int.TryParse - how?

I am trying to create a C-sharp program, that ask the user to pick a number between 1 and 3. It will then use that number to print one of three names I have in an array. This is how far I got:
string[] names = new string[] { "Peter", "John", "Paul" };

Console.Write("Select a number from 1-3: ");
string numberText = Console.ReadLine();

bool isValidNum = false;
int.TryParse(numberText, out int num)

do () {
    
} while (isValidNum == false);

I wanted the do-while to continue until the nubmerText is an actual number I can parse to Int, but also then be a valid number from 1-3 but I am kind of confused as to how to proceed.
Was this page helpful?