我一直在试图弄清楚当有人最终输入错误答案(在我的测验中)时如何让我的控制台关闭?
我试过 Environment.Exit(); 但它不起作用......它给了我错误:“方法'Exit'没有重载需要0个参数。
这是我的一些代码。我已经用注释标记了我希望退出代码的位置:
Console.WriteLine("In what country was Adolf Hitler born?");
string userAnswer = Console.ReadLine();
if (Answers.AnswerOne.Equals(userAnswer))
{
Console.WriteLine("Congratulations! {0} is the correct answer!", Answers.AnswerOne);
Console.WriteLine("\n\n(Press Enter to move on to the next question...)");
}
else if (!Answers.AnswerOne.Equals(userAnswer))
{
Console.WriteLine("Sorry! You wrote the wrong answer!\nThe correct answer was {0}.", Answers.AnswerOne);
Console.WriteLine("\n\n(Press Enter to exit...)");
Console.ReadKey();
//EXIT CONSOLE
}
否则,代码运行得很好。
提前致谢。