system pause in C#

方法一:

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

注:也可用ReadLine()或Read(),但是只能对回车进行响应,不能达到anykey的效果。

方法二:

1) 在源文件using处加入using System.Runtime.InteropServices;语句
2) 在类中前几行插入以下语句

[DllImport("msvcrt.dll")]
static extern bool system(string str);

3) 在需要的地方调用 system("pause");

方法三:

如果你使用的是VS,并且只是想要查看程序运行结果而不调试,使用 Ctrl+F5 即可。

原文地址:https://www.cnblogs.com/xfiver/p/1965288.html