How to stop C# console applications from closing automatically? [duplicate]

Solution 1:

Console.ReadLine();

or

Console.ReadKey();

ReadLine() waits for , ReadKey() waits for any key (except for modifier keys).

Edit: stole the key symbol from Darin.

Solution 2:

You can just compile (start debugging) your work with Ctrl+F5.

Try it. I always do it and the console shows me my results open on it. No additional code is needed.

Solution 3:

Try Ctrl + F5 in Visual Studio to run your program, this will add a pause with "Press any key to continue..." automatically without any Console.Readline() or ReadKey() functions.

Solution 4:

Console.ReadLine() to wait for the user to Enter or Console.ReadKey to wait for any key.