<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # C# 注釋 > 原文: [https://www.programiz.com/csharp-programming/comments](https://www.programiz.com/csharp-programming/comments) #### 在本文中,我們將學習 C# 注釋,不同樣式的注釋,以及為什么以及如何在程序中使用它們。 注釋在程序中使用,以幫助我們理解一段代碼。 它們是人類可讀的單詞,旨在使代碼可讀。 注釋被編譯器完全忽略。 在 C# 中,有 3 種類型的注釋: 1. 單行注釋(`//`) 2. 多行注釋(`/* */`) 3. XML 注釋(`///`) * * * ## 單行注釋 單行注釋以雙斜杠`//`開頭。 編譯器將忽略`//`之后到行尾的所有內容。 例如, ```cs int a = 5 + 7; // Adding 5 and 7 ``` 在這里,`Adding 5 and 7`是注釋。 ### 示例 1:使用單行注釋 ```cs // Hello World Program using System; namespace HelloWorld { class Program { public static void Main(string[] args) // Execution Starts from Main method { // Prints Hello World Console.WriteLine("Hello World!"); } } } ``` 上面的程序包含 3 條單行注釋: ```cs // Hello World Program // Execution Starts from Main method ``` 和 ```cs // Prints Hello World ``` 單行注釋可以寫在單獨的行中,也可以與代碼一起寫在同一行中。 但是,建議在單獨的行中使用注釋。 * * * ## 多行注釋 多行注釋以`/*`開頭,以`*/`結束。 多行注釋可以跨越多行。 ### 示例 2:使用多行注釋 ```cs /* This is a Hello World Program in C#. This program prints Hello World. */ using System; namespace HelloWorld { class Program { public static void Main(string[] args) { /* Prints Hello World */ Console.WriteLine("Hello World!"); } } } ``` 上面的程序包含 2 條多行注釋: ```cs /* This is a Hello World Program in C#. This program prints Hello World. */ ``` and ```cs /* Prints Hello World */ ``` 在這里,我們可能已經注意到,多行注釋不必跨越多行。 可以使用`/* … */`代替單行注釋。 * * * ## XML 文檔注釋 XML 文檔注釋是 C# 中的一項特殊功能。 它以三斜杠`///`開頭,用于分類描述一段代碼。這是使用注釋中的 XML 標記完成的。 這些注釋然后用于創建單獨的 XML 文檔文件。 如果您不熟悉 XML,請參閱[什么是 XML?](https://www.w3schools.com/xml/xml_whatis.asp "What is XML?") ### 示例 3:使用 XML 文檔注釋 ```cs /// <summary> /// This is a hello world program. /// </summary> using System; namespace HelloWorld { class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } ``` 上面程序中使用的 XML 注釋是 ```cs /// <summary> /// This is a hello world program. /// </summary> ``` 生成的 XML 文檔(`.xml`文件)將包含: ```cs <?xml version="1.0"?> <doc> <assembly> <name>HelloWorld</name> </assembly> <members> </members> </doc> ``` 如果您想了解更多信息,請訪問 [XML 文檔注釋](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments)。 * * * ## 以正確的方式使用注釋 注釋用于解釋部分代碼,但不應過度使用它們。 例如: ```cs // Prints Hello World Console.WriteLine("Hello World"); ``` 上面的示例中不必使用注釋。 很明顯,該行將打印 HelloWorld。 在這種情況下,應避免編寫注釋。 * 而是應在程序中使用注釋來解釋復雜的算法和技術。 * 注釋應簡短,切題而不是冗長的描述。 * 根據經驗,最好使用注釋解釋**為什么**而不是**做什么**。
                  <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>

                              哎呀哎呀视频在线观看