When I execute my program in Visual Studio (just a simple hello world app) it terminates and closes the console window immediately, rather than waiting for me to close it ma
This will work for sure: In old Visual studio 2010 and older, system properties were grandfathered from windows system, however 2010 and up this property was customized or set ti null. do the following and this will fix it for sure.
To do this select the project in the solution explorer on the right or left (probably is already selected so you don't have to worry about this). Then select "project" from the menu bar drop down menus, then select "*project_name* properties" > "configuration properties" > "linker" > "system" and set the first property, the drop down "subsystem" property to "console (/SUBSYSTEM:CONSOLE)". The console window should now stay open after execution as usual.
You are good to go NOW!!
While testing Console.ReadKey()
is nice to have. Here's an example:
namespace Foo
{
class Program
{
static void Main(string[] args)
{
Console.Write("The Console will close when it reads a key-input. "+
"Press a key to close");
Console.ReadKey();
}
}
}
This is by design and your instructor is incorrect. Try launching a .bat file from a folder view and you get precisely the same behaviour!
You can
Set a breakpoint
Ask for user input via
Console.Readline()
Run to cursor
You can set a breakpoint and start the application in Debug mode. This way the IDE will halt at the breakpoint and the window doesn't get closed until you continue the execution of your code.
Start in debug mode ;)