コードのコメント - // および /**/

C# では、2 つの異なる形式のコメントがサポートされています。 1 行のコメントは // で始まり、そのコード行の末尾で終了します。 複数行のコメントは /* で始まり、*/ で終了します。 次のコードは、それぞれの例を示しています。

// 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 */;
}

1 行のコメントは、同じ行の実行可能コードの後に配置できます。 コメントは、テキスト行の末尾で終了します。

return source++; // increment the source.

一部のコメントは、3 つのスラッシュ (///) で始まります。 "トリプルスラッシュのコメント" は "XML ドキュメント コメント" です。 コンパイラはこれらを読み取り、人間用のドキュメントを生成します。 XML ドキュメント コメントについて詳しくは、トリプルスラッシュのコメントに関するセクションを参照してください。