Comments are used to explain code and make it easier to understand. They are ignored by the compiler and do not affect program execution.
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
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");
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
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!