C#.NET Difference between // comments, /* */ comments and /// comments

Difference between // comments, /* */ comments and /// comments.

What are Comments?

- Comments are the portions of the code which is ignored by the compiler.

- It allows the user to make simple notes in the relevant areas of the source code.

- It is used for formal documentation for understanding particular code and its operation.

- It can be used to explain source code and to make it more readable.

Types of Comments:

1. Single-line comment (// )
2. Multi-line comment (/* */)
3. XML Documentation comment (///)

1. Single-line comment (// ):

- It can start with ' // '
- It is a single line comment.

Example:
main()
{
   cout<<"Hello world";   //'cout' is used for printing the output, it prints Hello world
}

- In the above example, with the // comment, describing the use of 'cout' statement.

2. Multi-line comment (/* */):

- It can start with /* and end with */.
- You can add multiple comments.
- Using this, you can nested one comment within the other comment.

Example:
/*cout<<"Hello world";
cout<<"How are you?";
*/

- In the above example, you can add multiple comments using multi-line comments.

3. XML Documentation comment (///):

- It is used for XML documentation.
- It provides information about code elements such as functions, fields and variables.

Example:
///<summary>
///   Example 1
///   Using <summary> rag
///</summary>
What are the ways to deploy an assembly? - C#.NET
C#.NET What are the ways to deploy an assembly? - MSI installer, CAB archive, XCOPY command...
Sorting the elements of the array in descending order - C#.NET
C#.NET - Sorting the elements of the array in descending order - You can do so by calling Sort() and then Reverse() methods...
System.String vs. System.StringBuilder classes - C#.NET
C#.NET System.String vs. System.StringBuilder classes - System.StringBuilder was designed with the purpose of having a mutable string...
Post your comment