<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # C# 基本語法 C# 是一種面向對象的編程語言。在面向對象的程序設計方法中,程序由各種相互交互的對象組成。相同種類的對象通常具有相同的類型,或者說,是在相同的 class 中。 例如,以 Rectangle(矩形)對象為例。它具有 length 和 width 屬性。根據設計,它可能需要接受這些屬性值、計算面積和顯示細節。 讓我們來看看一個 Rectangle(矩形)類的實現,并借此討論 C# 的基本語法: ``` using System; namespace RectangleApplication { class Rectangle { // 成員變量 double length; double width; public void Acceptdetails() { length = 4.5; width = 3.5; } public double GetArea() { return length * width; } public void Display() { Console.WriteLine("Length: {0}", length); Console.WriteLine("Width: {0}", width); Console.WriteLine("Area: {0}", GetArea()); } } class ExecuteRectangle { static void Main(string[] args) { Rectangle r = new Rectangle(); r.Acceptdetails(); r.Display(); Console.ReadLine(); } } } ``` 當上面的代碼被編譯和執行時,它會產生下列結果: ``` Length: 4.5 Width: 3.5 Area: 15.75 ``` ## _using_ 關鍵字 在任何 C# 程序中的第一條語句都是: ``` using System; ``` **using** 關鍵字用于在程序中包含命名空間。一個程序可以包含多個 using 語句。 ## _class_ 關鍵字 **class** 關鍵字用于聲明一個類。 ## C# 中的注釋 注釋是用于解釋代碼。編譯器會忽略注釋的條目。在 C# 程序中,多行注釋以 /* 開始,并以字符 */ 終止,如下所示: ``` /* This program demonstrates The basic syntax of C# programming Language */ ``` 單行注釋是用 '//' 符號表示。例如: ``` }//end class Rectangle ``` ## 成員變量 變量是類的屬性或數據成員,用于存儲數據。在上面的程序中,_Rectangle_ 類有兩個成員變量,名為 _length_ 和 _width_。 ## 成員函數 函數是一系列執行指定任務的語句。類的成員函數是在類內聲明的。我們舉例的類 Rectangle 包含了三個成員函數: _AcceptDetails_、_GetArea_ 和 _Display_。 ## 實例化一個類 在上面的程序中,類 _ExecuteRectangle_ 是一個包含 _Main()_ 方法和實例化 _Rectangle_ 類的類。 ## 標識符 標識符是用來識別類、變量、函數或任何其它用戶定義的項目。在 C# 中,類的命名必須遵循如下基本規則: * 標識符必須以字母開頭,后面可以跟一系列的字母、數字( 0 - 9 )或下劃線( _ )。標識符中的第一個字符不能是數字。 * 標識符必須不包含任何嵌入的空格或符號,比如 ? - +! @ # % ^ & * ( ) [ ] { } . ; : " ' / \。但是,可以使用下劃線( _ )。 * 標識符不能是 C# 關鍵字。 ## C# 關鍵字 關鍵字是 C# 編譯器預定義的保留字。這些關鍵字不能用作標識符,但是,如果您想使用這些關鍵字作為標識符,可以在關鍵字前面加上 @ 字符作為前綴。 在 C# 中,有些標識符在代碼的上下文中有特殊的意義,如 get 和 set,這些被稱為上下文關鍵字(contextual keywords)。 下表列出了 C# 中的保留關鍵字(Reserved Keywords)和上下文關鍵字(Contextual Keywords): | **保留關鍵字** | | --- | --- | --- | --- | --- | --- | --- | | abstract | as | base | bool | break | byte | case | | catch | char | checked | class | const | continue | decimal | | default | delegate | do | double | else | enum | event | | explicit | extern | false | finally | fixed | float | for | | foreach | goto | if | implicit | in | in (generic modifier) | int | | interface | internal | is | lock | long | namespace | new | | null | object | operator | out | out (generic modifier) | override | params | | private | protected | public | readonly | ref | return | sbyte | | sealed | short | sizeof | stackalloc | static | string | struct | | switch | this | throw | true | try | typeof | uint | | ulong | unchecked | unsafe | ushort | using | virtual | void | | volatile | while | | **上下文關鍵字** | | add | alias | ascending | descending | dynamic | from | get | | global | group | into | join | let | orderby | partial (type) | | partial (method) | remove | select | set |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看