Different types of comments in C#
Loading
Different types of comments in C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brahma Prakash ShuklaPosted Nov 9, 2022, 9:52 AM
In C#, there are 3 types of comments:
//)/* */)///)Mukesh NailwalPosted Nov 9, 2022, 6:46 AM
3 types of comments are in C#:
//)/* */)///)Example Single Line comments:
Example Multi Line comments:
Example XML comments:
Rajanikant HawaldarPosted Nov 9, 2022, 6:35 AM
There are 3 types of comments in C#, There are
1) Single line comments:
2) Multiple line comments
3) XML tags comments
https://www.c-sharpcorner.com/uploadfile/puranindia/comments-in-C-Sharp/
Uday DodiyaPosted Nov 9, 2022, 6:34 AM
Comments are used in a program to help us understand a piece of code. They are human readable words intended to make the code readable. Comments are completely ignored by the compiler.
In C#, there are 3 types of comments:
//)/* */)///)Single Line Comments
Single line comments start with a double slash
//. The compiler ignores everything after//to the end of the line. For example,Here,
Adding 5 and 7is the comment.Example 1: Using single line comment
The above program contains 3 single line comments:
and
Single line comments can be written in a separate line or along with the codes in same line. However, it is recommended to use comments in a separate line.
Multi Line Comments
Multi line comments start with
/*and ends with*/. Multi line comments can span over multiple lines.Example 2: Using multi line comment
The above program contains 2 multi line comments:
and
XML Documentation Comments
XML documentation comment is a special feature in C#. 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.If you are not familiar with XML, see What is XML?
Example 3: Using XML documentation comment
The XML comment used in the above program is
The XML documentation (.xml file) generated will contain:
Visit XML Documentation Comments if you are interested in learning more.
Use Comments the Right Way
Comments are used to explain parts of code but they should not be overused .
For example:
// Prints Hello World Console.WriteLine("Hello World");Using comment in the above example is not necessary. It is obvious that the line will print Hello World. Comments should be avoided in such cases.
Vishal YelvePosted Nov 9, 2022, 6:33 AM
In C#, there are 3 types of comments:
Single Line Comments ( // )
Multi Line Comments ( /* */ )
XML Comments ( /// )