Using comments in C#

Chapter 3,

USING COMMENTS


It is a best practice to use comments where ever possible in your code, comments help you in documenting the program so that in some later point when you review your code you actually remember what the code does and what is the logic behind the code.
Also it so happens that, applications are developed by a large team and the module/code written by you will be used by someone else to write another logic/program. The understanding of your code is greatly helped by your comments, and the time required to develop the application is greatly reduced.
Comments/Documentation also helps in maintenance of the application.

In C# there are two ways of commenting your code, the traditional C-Type inline single line comments(// ..)
and Multi-line comments (/* .. */)

Single Line comments:
using the single line inline comment only a single line is commented.
For example.

// int i;  this line is commented
   int j;

whenever the compiler encounters the two forward slashes , it ignores all the remaining characters following the slashes until the end of the line.

Multi Line comments:
Using the multi line commenting method , more than one line of code can be commented.
For example.

/* int i ;
    int j;
    int k;
*/

whenever the compiler encounters the forward slash and a Asterisk ( /* ) the compiler ignores all the characters until it encounters a asterisk followed by a forward slash ( */ ) which denotes the end of comment.

It is possible to include a multi line comments within a single line.








No comments:

Post a Comment