C sharp - C# comments

In C#, comments are used to explain code and make it more readable. There are three main types of comments:

1. Single-line Comments

Use // to start a single-line comment.

// This is a single-line comment
int x = 5; // This comment is after a statement

2. Multi-line (Block) Comments

Use /* ... */ to write comments that span multiple lines.

/* This is a multi-line comment
   It can span several lines */
int y = 10;

3. XML Documentation Comments

Use /// to create XML-style documentation comments. These are used to document code elements like classes and methods. Tools like Visual Studio and DocFX can generate documentation from these.

/// <summary>
/// Adds two integers.
/// </summary>
/// <param name="a">First integer</param>
/// <param name="b">Second integer</param>
/// <returns>The sum of a and b</returns>
public int Add(int a, int b)
{
    return a + b;
}