1

This may be a stupid question, but why do I need to use Console.ReadLine() to prevent the console from closing immediately? for instance, this program:

    namespace hello_world
    {
        class Program
        {
    static void Main(string[] args)
            {
                Console.WriteLine("Hello World!");
                Console.ReadLine();//without this, the console closes immediately
            }
        }
    }

The console closes almost as soon as it opens. My book doesn't compensate with this, and the Udemy video I am watching doesn't compensate with it either. None of my books C# even addressed this. I am using visual studio community 2015.

Tommy
  • 69
  • 4

1 Answers1

1

The console closes almost as soon as it opens.

Normally, this does not happen. This only happens when you run your app by pressing the start button with the little green triangle. Because what that button does is "Start with debugging". If you start with debugging, the console window closes after the program has finished running. To start without debugging, go to Debug -> Start without debugging

Sweeper
  • 213,210
  • 22
  • 193
  • 313