17

So our new teacher executes console applications (C#, .NET) with the VS debugger attached (F5) instead of just letting it execute normally (CTRL + F5).

He complained about the output not showing up (he still gave me full score at least) That's because executing with F5 simply ends the program after Main() is done executing, while CTRL + F5 leaves the window open until you press a key, saying "Press any key..."

So here's what I'm gonna put at the very bottom of Main() in future:

if (System.Diagnostics.Debugger.IsAttached)
{
Console.CursorVisible = false;
   Console.WriteLine("Press any key...");
   Console.ReadKey(true);
}

Comments
Add Comment