-1
我在程序中使用了try和catch方法,但我沒有規定用戶在輸入不正確的值時輸入的值。例如,用戶輸入一個字符串值,程序表示請輸入一個數字......然後程序不允許該用戶輸入一個新值。我能做什麼?我的代碼在這裏。謝謝。try&catch用於提供值
try
{
Console.Write("Please enter column number: ");
string str = Console.ReadLine();
int columno = int.Parse(str);
if (columno > 20)
{
Console.WriteLine("please enter a number between 1 and 20");
}
else
{
for (int j = 0; j < columno; j++)
{
Random rnd = new Random();
for (int i = 0; i < 6; i++)
{
int rndno = rnd.Next(1, 50);
Console.WriteLine(rndno);
}
}
}
}
catch
{
Console.WriteLine("please enter a number between 1 and 20", "Error");
}
Console.ReadLine();
}
}
}
用編程語言標記你的問題。 – csmckelvey
你的意思是你希望用戶被要求輸入值,直到它是一個正確的?或者只是關閉應用程序? –