How to avoid C# console applications from closing automatically.
-
One way is to interop it with msvcrt.dll
You can pinvoke this C function into your C# application. This process is very easy. There are a few steps:1) Insert System.Runtime.InteropServices to your using clauses.
2) Insert this line in your class (usually in the first few lines)[DllImport("msvcrt.dll")] static extern bool system(string str);3) In that same class, simply write this:
system("pause"); -
The simplest way that I always use is to ask for input
Console.ReadLine();or
Console.ReadKey();ReadLine() waits for ↩, ReadKey() waits for any key (except for modifier keys).

浙公网安备 33010602011771号