【发布时间】:2021-08-14 20:13:20
【问题描述】:
我有一个小问题。我想使用 close 方法关闭我的控制台。不是通过 X。
为此,我在 switch 块中有一个案例“9”;
这意味着当我输入“9”并按回车时,窗口应该关闭。之前尝试调用 Application.Close();用一个方法不起作用。
有没有人有解决方案,或者这甚至不能通过开关实现?
private void InputOption()
{
string input;
Menu nextMenu;
while(true) //Die Eingabe muss die zahlen beinhalten.
{
Console.Write("Eingabe: ");
input = Console.ReadLine();
bool correctInput = true;
switch(input)
{
case "1":
nextMenu = new CreateProfileMenu();
break;
case "2":
nextMenu = new LoadProfileMenu();
break;
case "9":
Close();
break;
default:
correctInput = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Ungültige Eingabe!");
Console.ForegroundColor = ConsoleColor.DarkCyan;
break;
}
if (correctInput)
{
break;
}
}
【问题讨论】:
标签: console switch-statement window