Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
I want to close my console using a close method. Not via the X

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;
            }
        }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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();
    }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda