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#

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

Conclusion

Hope the article would have helped you in understanding comments and their usage and importance in coding. Proper usage of comments makes your code easily to understand and improve performance.

Your feedback and constructive contributions are welcome. Please feel free to contact me for feedback or comments you may have about this article.