#29 – Comments
July 16, 2010 3 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:
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 //--------------------------------------
More
In fact Sean, comments are ignored by the compiler and therefore has no effect on the behavior of the program.
But they are so important for programmers. Taking 15 minutes to comment out your program, could save you 1 hour of headaches.
I absolutely agree–good comments are critical for professionally written code.
There’s another important comment type: the XML documentation for C# source codes.
///
///
///
///…
One more thing, comments are good and necessary, but sometimes a lot of comments may mean a low quality of source codes. High quality source codes do not need or need very little comments to explain what it does and how it does.
Anyway, comments are good things then none.