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(); } }
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.
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.
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.
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.
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With