Home > Software design >  How to stop command window from closing after hitting enter
How to stop command window from closing after hitting enter

Time:05-05

I am a complete beginner so I really have no idea what I'm doing.


namespace first_program
{
  class first_program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
      Console.ReadLine();
      Console.WriteLine("Hello World!");
    }
  }
} 

I am using VS Code and whenever I run this code the command prompt opens up, but whenever I press enter after typing into it the window closes.

Is there something wrong with my code? Or is it a bug with VS Studio?

I have copied all of this code from a Youtube tutorial by Brackeys titled "How to Program in C#"

It also my be important for me to note that a message saying "The program '[10260] first program.dll' has exited with code 0 (0x0)." pops up in the debug terminal.

CodePudding user response:

Place Console.ReadKey() after the writeLine stuff, and it will wait for a keyboard interaction to close.

CodePudding user response:

You can give it (https://www.youtube.com/watch?v=KZwVX34d0S0) a try. It helped me!

  • Related