C#idiomatic C#
commentscsharp/language-reference/tokens

Language

Code comments - `//` and `/*` - `*/`

You use "//" for single-line comments. You use "/*" to start multi-line comments that end with "*/". You add comments to explain your code.

  • page csharp/language-reference/tokens/comments
  • updated 01/14/2026

C# supports two different forms of comments. Single line comments start with // and end at the end of that line of code. Multiline comments start with /* and end with */.


ms.custom: "updateeachrelease"

The C# language reference documents the most recently released version of the C# language. It also contains initial documentation for features in public previews for the upcoming language release.

The documentation identifies any feature first introduced in the last three versions of the language or in current public previews.

The following code shows an example of each form:

sample 路 csharpdocs/csharp/language-reference/tokens/snippets/comments.csExampleComments

csharp


public class C
{
    // <ExampleComments>
    // 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
       */
    // </ExampleComments>

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

    public static int Increment(int source)
    {
        // <LineEndingComment>
        return source++; // increment the source.
        // </LineEndingComment>
    }

}

You can use a multiline comment to insert text in a line of code. Because these comments have an explicit closing character, you can include more executable code after the comment:

sample 路 csharpdocs/csharp/language-reference/tokens/snippets/comments.csInlineComment

csharp


public class C
{
    // <ExampleComments>
    // 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
       */
    // </ExampleComments>

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

    public static int Increment(int source)
    {
        // <LineEndingComment>
        return source++; // increment the source.
        // </LineEndingComment>
    }

}

A single line comment can appear after executable code on the same line. The comment ends at the end of the text line:

sample 路 csharpdocs/csharp/language-reference/tokens/snippets/comments.csLineEndingComment

csharp


public class C
{
    // <ExampleComments>
    // 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
       */
    // </ExampleComments>

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

    public static int Increment(int source)
    {
        // <LineEndingComment>
        return source++; // increment the source.
        // </LineEndingComment>
    }

}

Some comments start with three slashes: ///. Triple-slash comments are XML documentation comments. The compiler reads these comments to produce human documentation. You can read more about XML doc comments in the section on triple-slash comments.