I have a small problem. I want to close my console using a close method. Not via the X.
For this I have a case "9" in the switch block;
This means that when I enter "9" and press enter, the window should close. The previous attempts to call Application.Close(); with a method did not work.
Does anyone have a solution, or is this not even possible from the switch?
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;
}
}
I have found the problem. The assembly
I have found the error. There was a missing link to System.Windows.Forms;
I have now successfully implemented the method Close() in the Switch Block.
case "9" :
Close();
...
private void Close()
{
Application.Exit();
}