当用户输入字符串而不是整数时,它会给我和错误并使控制台崩溃。我不明白如何捕捉这个错误。如果发生此错误,我希望它做的是跳过玩家的回合。
Console.Write("Row (1-3): ");
int UserRowChoice = Convert.ToInt32(Console.ReadLine());
try { }
catch (InvalidCastException e) { ThrowError("You typed a string instead of an integer. You've lost your turn."); Console.ReadKey(); RunGame(T1, CurrentPlayer, Winner); }
if (UserRowChoice < 1 || UserRowChoice > 3)
{
ThrowError("You either typed a number that was less than 1 or greater than 3. You've lost your turn.");
Console.ReadKey();
RunGame(T1, CurrentPlayer, Winner);
}
qq_花开花谢_0
MMMHUHU
慕码人2483693
相关分类