程式碼註解 - ///**/

C# 支援兩種不同形式的註解。 單行註解開頭為 //,並在該程式碼結尾結束。 多行註解開頭為 /*,結尾為 */。 下列程式碼將顯示各項作業的範例:

// This is a single line comment.

/* This could be a summary of all the
   code that's in this class.
   You might add multiple paragraphs, or links to pages
   like https://learn.microsoft.com/dotnet/csharp.
   
   You could even include emojis. This example is 🔥
   Then, when you're done, close with
   */

多行註解也可以用於在程式碼中插入文字。 因為這些註解具有明確的結尾字元,所以您可以在註解之後包含更多可執行檔程式碼:

public static int Add(int left, int right)
{
    return left /* first operand */ + right /* second operand */;
}

單行註解可以在相同行上的可執行檔程式碼後面出現。 註解會在文字行結尾結束:

return source++; // increment the source.

有些註解開頭為三個斜線:///。 「三道斜線註解」XML 文件註解。 編譯器會讀取這些內容來產生人為文件。 您可以在三道斜線註解一節中深入了解 XML 文件註解