My input gets checked by "TryParse". And if it is false I want to let the user retype it correctly. But when I click any key after the check it deletes everything above cause of "Console.Clear();". - I want to delete only the input part and nothing above it.
namespace Practice
{
class Program
{
static void Main(string[] args) // Main Method
{
byte age1, age2;
string input;
do
{
Console.Write("Enter Age 1: "); input = Console.ReadLine();
if (!byte.TryParse(input, out age1)) Error();
} while (!byte.TryParse(input, out age1));
do
{
Console.Write("Enter Age 2: "); input = Console.ReadLine();
if (!byte.TryParse(input, out age1)) Error();
} while (!byte.TryParse(input, out age2));
}
static void Error()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Invalid Input...");
Console.ResetColor();
Console.ReadKey();
Console.Clear();
}
}
}