Comments in C#

Datatype Conversions in C#

In this tutorial, we are going to learn about implicit conversion, explicit conversion, parse and tryparse methods.

In this tutorial, we are going to learn about the comments in C#, various types of comments and uses of comments

When to use Comments?

Comments are used at the top of some blocks or lines of code that are difficult to understand .They are used to give an idea of what that block of code do.These are human- readable and understandable and C# compiler completely ignores comments.Comments are used to document what the program does and what specific blocks or lines of code do.

Different types of comments

In C#, mainly comments are of three types. They are
1.Single line comments
2. Multi Line comments
3. XML documentation comments

Single line comments

Single line comments are used when we want to comment a single line in the program.
Console.WriteLine(“Become A Geek”)
The above line normally writes the sentence “Become A Geek”(without quotes) to the console. If we comment the line the C# compiler simply ignores the line and doesn’t execute at all.

//Console.WriteLine(“Become A Geek”)
The slashes(//) infront of a line indicates that the line is commented.

Multi line comments

Multi line comments are used when we want to comment one or more lines.
/*Console.WriteLine(“Become A Geek”)
Console.writeline(“I will become a Geek”);*/

or we can comment using single line comments

//Console.WriteLine(“Become A Geek”)
//Console.writeline(“I will become a Geek”);

The signs (/*) and (*/) at the begining and end of the line shows that these are multi line comments

XML documentation comments

These are very helpful in C#. These are denoted with (///) three Forward slashes.

XML documentation coments in c#

XML documentation coments in c#

when we hover mouse over simpleFunction in line 7. It will show the details whatever we have written in the summary section of the class named simple function.

In C# the shortcut to comment a line or multi lines is ctrl+k and ctrl+c. To uncomment the shortcut is ctrl+k and ctrl+u

Leave a Reply

Your email address will not be published. Required fields are marked *