3.2 C#控制台应用程序的基本结构
我们看看:(原创)c#学习笔记02--编写c#程序02--控制台应用程序,中的代码,如下:
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(); } } }
可以看出,上一节讨论的所有语法元素这里都有。其中有分号、花括号、注释和适当的缩进。
这里要注意一下如何实现第2章介绍的代码突出显示功能,这对于Windows应用程序来说比较重要,因为它是一个非常有用的特性。要实现该功能,需要使用#region和#endregion关键字,来定义可以展开和折叠的代码区域的开头和结尾。例如,可以修改为ConsoleApplication1生成的代码,如下所示:
#region Using directives using System; using System.Collections.Generic; using System.Linq; using System.Text; #endregion
在样就可以把这些代码行折叠为一行,以后要查看其细节时,可以再改展开它。
note: 以#开头的任意关键字实际上都是一个预处理指令,严格地说并不是C#关键字。