...

/

Comments

Comments

In this lesson, we will go through the commenting conventions in C#.

Block Comments

Block comments should usually be avoided. For descriptions use of the /// comments to give C# standard descriptions is recommended. When you wish to use block comments you should use the following style:

Press + to interact
/* Line 1
* Line 2
* Line 3
*/

As this will set off the block visually from code for the (human) reader. Alternatively you might use this oldfashioned C style for single line comments, even though it is not recommended. In case you use this style, a line break should follow the comment, as it is hard to see code preceeded by comments in the same line:

Press + to interact
/* blah blah blah */

Block comments may be useful in rare cases. Generally block comments are useful for comment out large sections of code.

Single Line Comments

You should use the // comment style to “comment out” code (You can comment out a line by using command + / as a shortcut) . It may be used for commenting sections of code too. Single line comments must be indented to the indent level when they are used for code documentation. Commented out code should be commented out in the first line to enhance the visibility of commented out code.

A rule of thumb says that generally, the length of a comment should not exceed the length of the code. Don’t explain too much, as this is an indication of too complicated, potentially buggy, code.

Press + to interact
class HelloWorld
{
static void Main()
{
System.Console.WriteLine("Hello, World!"); // Prints Hello, World!
}
}