<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# 關鍵字和標識符 > 原文: [https://www.programiz.com/csharp-programming/keywords-identifiers](https://www.programiz.com/csharp-programming/keywords-identifiers) #### 在本教程中,我們將學習 C# 編程語言中的關鍵字(保留字)和標識符。 ## C# 關鍵字 關鍵字是預定義的保留字集,在程序中具有特殊含義。 關鍵字的含義不能更改,也不能直接用作程序中的標識符。 例如, ```cs long mobileNum; ``` 在此,`long`是關鍵字,`mobileNum`是變量(標識符)。`long`在 C# 中具有特殊含義,即,它用于聲明`long`類型的變量,并且該函數無法更改。 另外,不能將`long`,`int`,`char`等關鍵字用作標識符。 因此,我們不能有以下內容: ```cs long long; ``` C# 總共有 79 個關鍵字。 所有這些關鍵字都是小寫的。 這是所有 C# 關鍵字的完整列表。 ```cs 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 using static void volatile while ``` 盡管關鍵字是保留字,但是如果將`@`添加為前綴,它們可以用作標識符。 例如, ```cs int @void; ``` 上面的語句將創建類型為`int`的變量`@void`。 * * * ### 上下文關鍵字 除了常規關鍵字,C# 還具有 25 個上下文關鍵字。 上下文關鍵字在有限的程序上下文中具有特定含義,并且可以用作該上下文之外的標識符。 它們不是 C# 中的保留字。 ```cs add alias ascending async await descending dynamic from get global group into join let orderby partial (type) partial (method) remove select set value var when (filter condition) where (generic type constraint) yield ``` 如果您想了解每個關鍵字的功能,建議您訪問 [C# 關鍵字](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/index)(官方 C# 文檔)。 * * * ## C# 標識符 標識符是給變量,方法,類等實體的名稱。它們是程序中唯一標識元素的令牌。 例如, ```cs int value; ``` 在此,`value`是變量的名稱。 因此,它是一個標識符。 除非添加`@`作為前綴,否則保留的關鍵字不能用作標識符。 例如, ```cs int break; ``` 該語句將在編譯時生成錯誤。 要了解有關變量的更多信息,請訪問 [C# 變量](/csharp-programming/variables-primitive-data-types "C# variables")。 * * * ## 命名標識符的規則 * 標識符不能是 C# 關鍵字。 * 標識符必須以字母,下劃線或`@`符號開頭。 標識符的其余部分可以包含字母,數字和下劃線符號。 * 不允許使用空格。 除字母,數字和下劃線外,它都不能有其他符號。 * 標識符區分大小寫。 因此,`getName`,`GetName`和`getname`代表 3 個不同的標識符。 以下是一些有效和無效的標識符: | 標識符 | 備注 | | --- | --- | | `number` | 有效 | | `calculateMarks` | 有效 | | `hello$` | 無效(包含`$`) | | `name1` | 有效 | | `@if` | 有效(關鍵字前綴為`@`) | | `if` | 無效(C# 關鍵字) | | `My name` | 無效(包含空格) | | `_hello_hi` | 有效 | * * * ## 示例:在程序中查找關鍵字和標識符的列表 為了澄清概念,讓我們在 [C# Hello World](/csharp-programming/hello-world "C# Hello World Program") 中編寫的程序中找到關鍵字和標識符的列表。 ```cs using System; namespace HelloWorld { class Hello { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } ``` | 關鍵詞 | 標識符 | | --- | --- | | `using` | `System` | | `namespace` | `HelloWorld`(命名空間) | | `class` | `Hello`(類) | | `static` | `Main`(方法) | | `void` | `args` | | `string` | `Console` | | ? | `WriteLine` | `WriteLine`方法內的`"Hello World!"`是字符串字面值。
                  <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>

                              哎呀哎呀视频在线观看