【发布时间】:2017-06-03 07:11:43
【问题描述】:
这可能是一个愚蠢的问题,但为什么我需要使用 Console.ReadLine() 来防止控制台立即关闭?比如这个程序:
namespace hello_world
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();//without this, the console closes immediately
}
}
}
控制台几乎一打开就关闭。我的书无法弥补这一点,我正在观看的 Udemy 视频也无法弥补这一点。我的 C# 书籍都没有解决这个问题。我正在使用 Visual Studio Community 2015。
【问题讨论】:
-
称为块。在没有 ReadLine() 的情况下,程序将在您读取结果之前终止;
-
使用 Ctrl + F5 运行您的程序,最后您将不需要 Console.ReadLine()。