What is the command to exit a Console application in C#?

前端 未结 4 927
梦如初夏
梦如初夏 2020-11-29 17:18

What is the command in C# for exit a Console Application?

4条回答
  •  生来不讨喜
    2020-11-29 17:22

    Console applications will exit when the main function has finished running. A "return" will achieve this.

        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("I'm running!");
                return; //This will exit the console application's running thread
            }
        }
    

    If you're returning an error code you can do it this way, which is accessible from functions outside of the initial thread:

        System.Environment.Exit(-1);
    

提交回复
热议问题