Comments in C# | Different Types Of Comments in C#
Comments are that block of code that is used for program documentation and those line(s) of code is ignored by compiler while execution.
There are three ways of commenting in C#.
- Single Line Comment
- MultiLine Comment
- XML documentation comment
1. Single Line Comment in C#:
When you just want to comment of only a single line and not more. For single line comment use “// “.
Ex :
//Console.WriteLine("Hello"); Console.WriteLine("World");
Here the “world” will get printed but hello will not printed as you have by commenting asked the compiler to avoid that particular line.
2. MultiLine Comment in C#:
If you want to comment more than single line of code, you should put the lines between /* … ….*/.
Ex :
/* Console.WriteLine(“Hello”); Console.WriteLine(“World”); */
Now in this case, nothing will be printed.
3. XML documentation Comment in C#:
Use /// to get the XML documentation of visual studio to detect it. There is more to it but not currently in scope of this article.