代码注释 - ///**/

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 文档注释 的详细信息。