(原创)c#学习笔记02--编写c#程序02--控制台应用程序

2.2  控制台应用程序

  在本解说中,将创建一个简单的控制台应用程序。创建方法参考:(原创)c#学习笔记02--编写c#程序01--开发环境

  创建成功后,在主窗口显示的文件里添加如下代码行:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Output text to the screen.
            Console.WriteLine( "The first app in Beginning c# Programming!" );
            Console.ReadKey(); 
        }
    }
}

 

  选择 “调试➪启动调试” (Debug➪Start Debugging)菜单项,运行结果如下图所示:

  按下任意键,退出应用程序(首先需要单击控制台窗口,以激活它)。

 

  控制台应用程序会在执行完毕后立即终止,如果直接通过IDE运行它们,就无法看到运行的结果。为了解决上例中的这个问题,使用 

Console.ReadKey(); 

告诉代码在结束前等待按键。

posted @ 2015-10-16 15:28  星月相随  阅读(375)  评论(0编辑  收藏  举报