输出屏幕在 C# 控制台应用程序中突然消失? [英] Output screen disappears suddenly in C# console application?
问题描述
我正在 VS 2013 中编写一个简单的 C# 控制台应用程序,但问题是输出屏幕闪烁片刻然后突然消失.我使用另一种方式并最终编写 Console.Readline() 方法并解决了问题.所以我个人认为这只是停止屏幕的技巧而不是正确的方式.所以任何人都可以以正确的方式解释我这样做??
I am writing a simple C# console application in VS 2013 but the problem is that output screen flashes for a moment and disappears suddenly . I use the alternate way and write Console.Readline() method in the end and problem is fixed .So but i personally think that this is just a trick to stop the screen and not the proper way.So can anyone explain me the proper way of doing this ??
推荐答案
程序立即关闭,因为没有任何东西阻止它关闭.在return 0;
处插入断点或在return 0;
前添加Console.Read();
,防止程序关闭.
The program immediately closes because there's nothing stopping it from closing. Insert a breakpoint at return 0;
or add Console.Read();
before return 0;
to prevent the program from closing.
完成程序后,按 Ctrl+F5(不带调试).这将在关闭窗口之前提示,这是你想要什么.
After you are done with your program, press Ctrl+F5 ( Run without debugging). This will prompt before closing the window and this is what you want.
或在最后使用这一行
Console.ReadKey();
这篇关于输出屏幕在 C# 控制台应用程序中突然消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!