Command line window closing with visual studio

samipink

Distinguished
Feb 3, 2011
1
0
18,510
Hi
I am new to C# and visual studio. I tried creating a new project and inserted the "hello World! program as shown below.
But when I run it the command window opens and closes without me being able to see it.

Help please
 
You need to pause the program before it ends so that you can see the output. You can do this by setting a breakpoint at the end of the "Main" function or, easier, insert the line:

string s = System.Console.ReadLine();

right at the end of the "Main" function. This will then wait for you to press the "Return" key before closing the command window.
 

jprahman

Distinguished
May 17, 2010
775
0
19,060
You can also use Thread.Sleep(xxxx) to cause execution to pause a certain number of milliseconds before closing. You could use Thread.Sleep() alone or in conjunction with System.Console.ReadLine() to close the console however you'd like.