位置:首頁 > 軟件操作教程 > 編程開發(fā) > C# > 問題詳情

C#控制臺應用程序的基本結構

提問人:劉團圓發(fā)布時間:2020-11-12

下面看看控制臺應用程序示例(ConsoleApplicationl),并研究一下它的結構。其代碼如下所不:

using System;

using System,Collections.Generic; 

using System.Linq; 

using System.Text; 

using System.Threading.Tasks; 

namespace ConsoleApplicationl

{

    class Program

    {

        static void Main(stringt] args)

         {

             // Output text to the screen.

            Console.WriteLine(MThe first app in Beginning C# Programming!u);

            Console.ReadKey{)?

 目前看來,這段代碼中最重要的部分如下所示:

static void Main(string[] args)

{

     // Output text to the screen.

    Console.WriteLine{"The first app in Beginning C# Programming!"};

    Console.ReadKey();

}

當運行控制臺應用程序時,就會執(zhí)行這段代碼,更確切地講,是運行花括號中的代碼塊^如前所述,注釋 行不做任何事情,包含它們只為了保持代碼的清晰。其他兩行代碼在控制臺窗口中輸出一些文本,并等待一個 響應。但目前我們還不需要關心它的具體機制。

這里要注意一下如何實現(xiàn)代碼大綱功能(雖然在第2章中介紹的是Windows應用程序的代碼 大綱功能),因為它是一個非常有用的特性。要實現(xiàn)該功能,需要使用#region和#6:1辦叫丨011關鍵字來定義可以展 開和折疊的代碼區(qū)域的開頭和結尾。例如,可以修改針對ConsoleApplicationl生成的代碼,如下所示:

#region Using directives

using System;

using System.Collections-Generic; 

using System.Linq; 

using System.Text; 

using System.Threading.Tasks;

#endregion

這樣就可以把這些代碼行折疊為一行,以后要查看其細節(jié)時,可以再次展開它。

繼續(xù)查找其他問題的答案?

相關視頻回答
回復(0)
返回頂部