Edit

Share via


Code comments - // and /* - */

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 */.

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.

Tip

To find when a feature was first introduced in C#, consult the article on the C# language version history.

The following code shows an example of each form:

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

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:

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

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

return source++; // increment the source.

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.