I have simple function of input validation:
private static int GetInt()
{
int tryInt;
while (true)
{
if (int.TryParse(Console.ReadLine(), out tryInt))
return tryInt;
else
Console.Write("Try again:");
}
}
I want to pass in criteria (let's say I want odd numbers, more than 20) How can I do it? Should I?
private static int GetInt(< criteria >)
{
int tryInt;
while (true)
{
if (int.TryParse(Console.ReadLine(), out tryInt) && < criteria >)
return tryInt;
else
Console.Write("Try again:");
}
}