The correct way to exit the console application

I read here and here , and I'm still confused if I should use Enviorment.Exit()in my console application.

In the method, I have the following code, if the user enters exit at the prompt,

if(userSelect == "exit"){
{
    Environment.Exit(0);
}

Update:

class Program
    {
        public static void Main(string[] args)
        {

            Console.WriteLine("Welcome to my Console App");
            Console.WriteLine();
            consoleManager();

        }


        public static void consoleManager()
        {
            string consolePrompt="ConsoleApp">";


            string whichMethod="";
            Console.Write(consolePrompt);
            whichMethod = Console.ReadLine();

            if(whichMethod == "view enties")
            {           
                viewEntry();
            }
            else
                if(whichMethod == "Add Entry")
                {
                    addEntry();
                }
                else
                    if(whichMethod == "exit"){
                    {
                        //what to do here
                    }
                }
            else{
                help();
            }
        }
+4
source share
1 answer

Go to the MSDN documentation for Environment.Exit , it explains the parameter

exitCode, , . , . , 1, , , 2 , .

, "" (0), , - . - , , . Environment.Exit(0) .

Edit , . -

  • Main, .
  • Enviorment.Exit(), return , .
  • , void Main(string[] args) int Main(string[] args). - . , , 0 . , .
  • - . dos, , . - , .
+3

Source: https://habr.com/ru/post/1628727/


All Articles