CHASH Tutorial



C# COMMENTS


Comments in C#

Comments are used to explain code and make it easier to understand. They are ignored by the compiler and do not affect program execution.

1. Single-line Comments

Start the line with //. Everything after // on that line is considered a comment.

// This is a single-line comment
Console.WriteLine("Hello World"); // This prints text to the console

  

2. Multi-line Comments

Use /* to start and */ to end a multi-line comment block.

/*
This is a multi-line comment.
It can span several lines.
Useful for longer explanations.
*/
Console.WriteLine("Hello World");

  

3. XML Documentation Comments

Special comments used to generate documentation for your code. Start with ///.

/// 
/// This method adds two integers and returns the sum.
/// 
/// First number
/// Second number
/// The sum of a and b
public int Add(int a, int b)
{
    return a + b;
}

  

Summary

  • Single-line comments (//): Brief explanations on a single line.
  • Multi-line comments (/* ... */): Block comments spanning multiple lines.
  • XML documentation comments (///): Used for automatic code documentation.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review