Press "Enter" to skip to content

How to Keep Console Window Open in Visual Studio?

In the Visual Studio, you are writing a C# (C-Sharp) program to print text on the console window using Console.WriteLine() method. But when you are running the application using the Start button or by pressing F5 (debug mode), console window closes automatically. Here is how you can keep the console window open in Visual Studio in debug mode and in without debug mode.

To Keep Console Window Open in Debug Mode

When you run the application by pressing the Start button or by pressing F5, the Visual Studio executes the application in debug mode. To keep the console window active you should put the Console.ReadLine() command below the Console.WriteLine() command in your C# program as shown in the below example:

class Hello
{
    static void Main(string[] args)
    {
        System.Console.WriteLine("Hello World!");
	System.Console.ReadLine();
    }
}

Output

Hello World!
_

Run Application Without Debugging To Keep Console Window Open

To keep the console window open in Visual Studio without using the Console.ReadLine() method, you should run the application without debug mode by pressing Ctrl+F5 or by clicking on the menu Debug > Start without Debugging option. This way the application remains active below until the user presses a key.

class Hello
{
    static void Main(string[] args)
    {
        System.Console.WriteLine("Hello World!");
    }
}

Output

Hello World!
Press any key to continue . . .

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

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