Visual Studio: Prevent console application window from closing
| Visual Studio |
You have just run your first console application in Visual Studio debug mode. But, the window closes before you can see the results!
[edit]
Start without debugging
The easiest way of avoiding the problem is to start your console application from Visual Studio without using debugging. To do this, select Start Without Debugging from the Debug menu (CTRL-F5). This time when the program ends execution, the window will remain open until you press any key on the keyboard.
[edit]
Wait for console input
Or, you can add this line of C# code at the end your application:
Console.ReadKey();
This will cause you application to wait until a key is pressed on the keyboard; and, then exit.