Comments are used for explaining the code and are used in a similar manner as in Java, C or C++. Compilers ignore the comment entries and do not execute them. Generally, programming languages contain two types of comments but in C#, there are 3 Types of comments :
-
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.
Syntax :// Single Line Comments
-
Multiline Comments : It is used to comment more than one line. Generally this is used to comment out an entire block of code statements.
Syntax :/* Multiline Comment */
Example :
// C# program to demonstrate the single// line and multiline commentsusingSystem;namespaceHelloGeeksApp {classHelloGeeks {// Single Line Comment -- Function to print MessagepublicstaticvoidMessage(stringmessage){Console.WriteLine(message);}// Main functionstaticvoidMain(string[] args){/* Multiline Comment --Define a variable ofstring type and assignvalue to it*/stringmsg ="GeeksforGeeks";// Calling functionMessage(msg);}}}chevron_rightfilter_noneOutput:
GeeksforGeeks
-
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. XML elements are added in XML Documentation Comments of C#. For more details refer to XML Documentation Comments in C#
Syntax :/// <summary> /// This class does something of program Summary. /// </summary>
Example :
// C# program to demonstrate XML// Documentation CommentsusingSystem;namespaceHelloGeeksApp {classHelloGeeks {/// <summary>/// Method to Display Geeksforgeeks Message/// </summary>/// <param name="Geeksforgeeks"></param>publicstaticvoidMessage(stringmessage){Console.WriteLine(message);}// Main functionstaticvoidMain(string[] args){/* Define a variable ofstring type and assignvalue to it*/stringmsg ="GeeksforGeeks";// Calling functionMessage(msg);}}}chevron_rightfilter_noneOutput:GeeksforGeeks
Note : The <summary> tag provides the information about the defined a type or member and <param> tag is method parameters.
Related Articles:
Recommended Posts:
- C#- Nested loops
- C# - Infinite Loop
- C# - if else Statement
- C# - if Statement
- C# - continue Statement
- C# - Break statement
- Differences Between .NET Core and .NET Framework
- C# - Indexers Using String as an Index
- Different Types of HTML Helpers in ASP.NET MVC
- Difference Between .NET and ASP.NET Framework
- Difference Between Properties and Indexers in C#
- C# Coding Standards
- C# Program to Convert a Binary String to an Integer
- Basics of FileStream in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
