How to exit from a console application

Use Environment.Exit to immediately return from a console application with a specified result code.

using System;

namespace ConsoleApplication1
  class Class1
    static void Main(string[] args)
      Console.WriteLine(“About to exit”);

      int exitCode = 0;

      // This line is not executed.
      Console.WriteLine(“After exit”);

Leave a Reply

Your email address will not be published. Required fields are marked *