Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!