Comments in C#
Comments:
àComments
are used in a program to help developers understand a piece of code.
àThey are human readable words intended
to make the code readable.
àCompilers
ignore the comment entries and do not execute them.
In C#, there are 3 types of comments:
(i)
Single Line Comments ( //
).
(ii)
Multi Line Comments (/* */).
(iii)
XML Comments ( /// ).
(i)
Single Line Comments:
àIt
is used to comment a single line.
àThese
comment can be written in a separate line or along with the codes in the same
line. But for better understanding always use the comment in a separate line.
àSingle
line comments start with a double slash //. The compiler ignores everything
after // to the end of the line.
Example,
int a = 5 + 7; // Adding 5 and 7. Here, Adding 5
and 7 is the comment.
(ii)
Multi Line Comments:
àIt
is used to comment more than one line. Generally this is used to comment out an
entire block of code statements.
àMulti
line comments start with /* and ends with */.
àMulti
line comments can span over multiple lines.
Example:
/*
This is a
Multi-line comments.
*/
(iii)
XML Documentation Comments:
àIt is a special type of
comment in C# and used to create the documentation of C# code by adding XML
elements in the source code.
àIt starts with a triple
slash /// and is used to categorically describe a piece of code.. This is done
using XML tags within a comment. These comments are then, used to create a
separate XML documentation file.
Example:
/// <summary>
/// this is a XML comments.
/// </summary>
Comments
Post a Comment