Comments can be used to document what the program does and what specific blocks or lines of code do. Since the C# compiler ignores comments, you can include them anywhere in a program without affecting your code.
How to comment in C#?
A comment is preceded by a double forward slash. The code of line after the double forward slash is simply ignored by the compiler.
We have following types of comments in C#
- Single line comments
// for single line comments
- Multiple line comments
/* for multi line comments */
- XML tags comments
/// XML tags displayed in a code comment
To code a comment, type a double forward slash followed by the comment. You can use this technique to add a comment on its own line or to add a comment after the code on a line.
Often when you code, you may want to comment out an entire block of code statements. Under normal circumstances, to do so you must Comment out each line individually.
Another way to comment out one or more lines of code to select the lines and click on the Comment or UnComment button in the Text Editor toolbar.
Shortcut: You can use Ctrl+K, Ctrl+C and Ctrl+K, Ctrl+U to Comment or Uncomment selected lines of text.
Tips to Comment your code
- Use comments only for portions of code that are difficult to understand
- Comments are used to help document what a program does and what the code with it does. Keep the comments simple and direct. Avoid ASCII art, jokes, poetry and hyper verbosity.
- Make sure that your comments are correct and up-to-date. There is no point in commenting correctly on code if the comments are not changed with the code. Both code and comments must move in parallel, otherwise the comments will actually make life more difficult for developers who maintain your code.
- During testing, you can comment out lines of code by coding an apostrophe before them. This is useful for testing new statements without deleting the old statement.
- Align comments in consecutive lines
For multiple lines of code with trailing comments, align the comments so they will be easy to read.const int level = 100; // The level mark is constant to 100 can't be changed const decimal turnaround = 45.67; // The turnaround is constant and can't be placed more
Some developers use tabs to align comments, while others use spaces. Because tab stops can vary among editors and IDEs, the best approach is to use spaces.

Dinesh GabhanePosted Nov 12, 2019, 11:58 PM
Good One. Thanks
lenin christPosted May 9, 2018, 12:48 AM
Hi, thanks for posting a tips-full article, I had learned more things on this blog, Keep on blogging, thanks .
Alex ANealsPosted Apr 25, 2018, 4:10 PM
Should tell why not what code does
vikas kumarPosted Feb 16, 2016, 4:13 AM
hello