閱讀英文

共用方式為


程式代碼批註 - ///**/

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 檔批注