Comments in C#
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 */ 
- 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#.
 Syntax :/// <summary> /// This class does something of program Summary. /// </summary> 
Example :
| // C# program to demonstrate XML // Documentation Comments  usingSystem;  namespaceSSMInfotech {       classHelloSSM {        /// <summary>     /// Method to Display SSM Infotech Solutions Message     /// </summary>     /// <param name="message"></param>     publicstaticvoidMessage(stringmessage)     {         Console.WriteLine(message);     }           // Main function     staticvoidMain(string[] args)     {                   /* Define a variable of            string type and assign            value to it*/        stringmsg = "SSM Infotech Solutions";                   // Calling function         Message(msg);     } } }  | 
Output:
SSM Infotech Solutions
Note : The <summary> tag provides the information about the defined a type or member and <param> tag is method parameters.
Last modified: Thursday, 31 December 2020, 4:51 PM
