日期:2014-05-18  浏览次数:20951 次

初学 C# 求问 控制台程序为啥运行之后闪一下就消失
以下是源代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace hellotomorrow
{
  class Program
  {
  static void Main(string[] args)
  {
  //Console.WriteLine("hello tomorrow!");
   
  }
  }
}
不知道咋回事任何一个控制台程序运行之后闪一下就消失了

------解决方案--------------------
Main 方法执行完了,程序自然就退出了,可以在最后加上一行
C# code
static void Main(string[] args)
{
    Console.WriteLine("hello tomorrow!");
    Console.ReadKey();
}

------解决方案--------------------
加一句Console.ReadLine();,让他停在那,否则在调试环境下直接返回了,在外部运行是正常的(ctrl+F5)
------解决方案--------------------
因为你没加上Console.ReadKey();
CMD执行完了你的Console.WriteLine();之后就退出了..
所以需要加上一行Console.ReadKey();
等待输入之后再结束..
------解决方案--------------------
直接Ctrl+F5执行,就可以不加Console.ReadKey();~