Visual Studio命令行为什么一闪而过

很多朋友在初次接触Visual Studio的时候,都会写一个Hello World程序,当执行时,黑色的窗口一闪而过,这是为什么呢?

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 namespace HelloWorld
6 {
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 Console.WriteLine("Hello, world");
12 }
13 }
14 }

问题是你执行时按的是F5,而正确的应该是Ctrl+F5,这样窗口就会显示 Press any key to continue...这句话了。也可以看到程序运行的结果了。
知道了解决方法,那么原因是什么呢?

原来,F5是Debugging模式,在这个模式下,当程序运行结束后,窗口不会继续保持打开状态。

而Ctrl+F5是 Start Without Debugging模式,在这个模式下,就可以看到运行结果了。

原文地址:https://www.cnblogs.com/humaoxiao/p/2361932.html