Comments

Comments in a C# program denote text that is ignored by the compiler and therefore has no effect on the behavior of the program.
There are two types of comments in C#:
  • Single line comments:  start with //, extend to end of line
  • Delimited comments:  surrounded by /*  */, can span multiple lines
Examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string s1 = "Hi";        // This is a single-line comment
 
/*  Multiple line
 *  comment.  Nice convention to use
 *  asterisk at the start of each line. */
 
string s2 = "/* This is a string, rather than a comment */";
string s3 = "// same here";
 
// Nested comments /* ignored */
 
//--------------------------------------
// Even better style for block comment
//--------------------------------------