Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep console window open

When I run my program, the console window seems to run and close. How to keep it open so I can see the results?

class Program {     public class StringAddString            {                                 public virtual void AddString()         {             var strings2 = new string[] { "1", "2", "3", "4", "5","6", "7", "8", "9"};              Console.WriteLine(strings2);             Console.ReadLine();         }     }      static void Main(string[] args)     {                   StringAddString s = new StringAddString();                 } } 
like image 738
user1929393 Avatar asked Jun 06 '13 02:06

user1929393


People also ask

How do I keep the console open?

Keep Console Open With the Ctrl + F5 Shortcut in C# The best approach for keeping our console window open after the execution of code is to run it with the Ctrl + F5 shortcut of the Microsoft Visual Studio IDE.

How do I stop my console window from closing?

You can simply press Ctrl + F5 instead of F5 to run the built code. Then it will prompt you to press any key to continue. Or you can use this line -> system("pause"); at the end of the code to make it wait until you press any key.

How do I keep the console window open in Visual Studio?

Start the project with Ctrl + F5 instead of just F5 . The console window will now stay open with the Press any key to continue . . . message after the program exits.

How do I stop the console window from closing in C++?

Before the end of your code, insert this line: system("pause"); This will keep the console until you hit a key. It also printed "Press any key to continue . . ." for me.


1 Answers

Put a Console.Read() as the last line in your program. That will prevent it from closing until you press a key

static void Main(string[] args) {     StringAddString s = new StringAddString();     Console.Read();             } 
like image 55
TGH Avatar answered Sep 21 '22 04:09

TGH