本文翻译自:How to stop C# console applications from closing automatically? [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
My console applications on Visual Studio are closing automatically, so I'd like to use something like C's system("PAUSE")
to "pause" the applications at the end of its execution, how can I achieve that? Visual Studio上的我的控制台应用程序正在自动关闭,因此我想使用C system("PAUSE")
类的东西在执行结束时“暂停”应用程序,我该如何实现?
#1楼
参考:https://stackoom.com/question/mJ0f/如何阻止C-控制台应用程序自动关闭-重复
#2楼
Console.ReadLine()
等待用户进入或Console.ReadKey
等待任何键。
#3楼
Console.ReadLine();
or 要么
Console.ReadKey();
ReadLine()
waits for ↩ , ReadKey()
waits for any key (except for modifier keys). ReadLine()
等待↩, ReadKey()
等待的任意键(除修改键)。
Edit: stole the key symbol from Darin. 编辑:偷走了达林的钥匙符号。
#4楼
Use: 使用:
Console.ReadKey();
For it to close when someone presses any key, or: 当有人按任意键时关闭它,或者:
Console.ReadLine();
For when the user types something and presses enter. 当用户输入内容并按下回车键时。
#5楼
You can just compile (start debugging) your work with Ctrl + F5 . 您可以使用Ctrl + F5编译(开始调试)您的工作。
Try it. 试试吧。 I always do it and the console shows me my results open on it. 我总是这样做,控制台告诉我我的结果是打开的。 No additional code is needed. 无需其他代码。
#6楼
在Visual Studio中尝试使用Ctrl + F5来运行程序,这将在没有任何Console.Readline()或ReadKey()函数的情况下自动添加“按任意键继续...”的暂停。