Reputation: 46831
This is probably an easy Visual Studio question, but I couldn't find it on the site.
When I "Start Debugging" a console program, it immediately exits when its finished. Is there any way to have it pause when it ends without putting an explicit pause command at the end of your program?
Upvotes: 8
Views: 9011
Reputation: 21
In visual studio 2019 you can disable closing automatically after finishing execution.
uncheck "Automatically close the console when debugging stops"
Upvotes: 0
Reputation: 40512
yes as @matthew said Console.ReadKey() will wait for your input after executing program, but you can use Console.ReadLine() which will terminate only if <ENTER> key is pressed:
void main()
{
Console.WriteLine("Hello World!"); //:)
Console.ReadLine();//this will do the trick.
}
Upvotes: 1
Reputation: 1970
You can place Console.ReadLine at the end of the program. That will force program to wait for a newline character input. Or you can place breakpoint at the end of the probram.
Upvotes: 6
Reputation: 8016
Console.ReadKey() should do it. It will pause the execution of your program until a key is pressed on the keyboard.
Upvotes: 1
Reputation: 117350
"Run without Debugging" does that, but I guess you want to debug still :)
Upvotes: 3