Comments in C# - GeeksforGeeks

07 May, 2019
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 CommentsMultiline 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 commentsusing System;  namespace HelloGeeksApp {      class HelloGeeks {       // Single Line Comment -- Function to print Message    public static void Message(string message)    {        Console.WriteLine(message);    }          // Main function    static void Main(string[] args)    {                  /* Multiline Comment --           Define a variable of           string type and assign           value to it*/        string msg = "GeeksforGeeks";                  // Calling function        Message(msg);    }}}Output: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 Comments using System;  namespace HelloGeeksApp {       class HelloGeeks {        /// <summary>    /// Method to Display Geeksforgeeks Message    /// </summary>    /// <param name="Geeksforgeeks"></param>    public static void Message(string message)    {        Console.WriteLine(message);    }           // Main function    static void Main(string[] args)    {                   /* Define a variable of           string type and assign           value to it*/        string msg = "GeeksforGeeks";                   // Calling function        Message(msg);    }}}Output:GeeksforGeeks

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
// 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 commentsusing System;  namespace HelloGeeksApp {      class HelloGeeks {       // Single Line Comment -- Function to print Message    public static void Message(string message)    {        Console.WriteLine(message);    }          // Main function    static void Main(string[] args)    {                  /* Multiline Comment --           Define a variable of           string type and assign           value to it*/        string msg = "GeeksforGeeks";                  // Calling function        Message(msg);    }}}Output:GeeksforGeeks

/* Multiline
Comment */

Example :
// C# program to demonstrate the single // line and multiline commentsusing System;  namespace HelloGeeksApp {      class HelloGeeks {       // Single Line Comment -- Function to print Message    public static void Message(string message)    {        Console.WriteLine(message);    }          // Main function    static void Main(string[] args)    {                  /* Multiline Comment --           Define a variable of           string type and assign           value to it*/        string msg = "GeeksforGeeks";                  // Calling function        Message(msg);    }}}
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 Comments using System;  namespace HelloGeeksApp {       class HelloGeeks {        /// <summary>    /// Method to Display Geeksforgeeks Message    /// </summary>    /// <param name="Geeksforgeeks"></param>    public static void Message(string message)    {        Console.WriteLine(message);    }           // Main function    static void Main(string[] args)    {                   /* Define a variable of           string type and assign           value to it*/        string msg = "GeeksforGeeks";                   // Calling function        Message(msg);    }}}Output:GeeksforGeeks

/// <summary>
/// This class does something of program Summary.
/// </summary>

Example :
// C# program to demonstrate XML// Documentation Comments using System;  namespace HelloGeeksApp {       class HelloGeeks {        /// <summary>    /// Method to Display Geeksforgeeks Message    /// </summary>    /// <param name="Geeksforgeeks"></param>    public static void Message(string message)    {        Console.WriteLine(message);    }           // Main function    static void Main(string[] args)    {                   /* Define a variable of           string type and assign           value to it*/        string msg = "GeeksforGeeks";                   // Calling function        Message(msg);    }}}
GeeksforGeeks

Note : The <summary> tag provides the information about the defined a type or member and <param> tag is method parameters.
Related Articles:
Comments in Java
Comments in SQL
Comments in HTML
Akanksha_Rai
CSharp-Basics
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
C# | Method Overriding
C# Dictionary with examples
Difference between Ref and Out keywords in C#
C# | Delegates
Top 50 C# Interview Questions & Answers
Extension Method in C#
Introduction to .NET Framework
C# | Abstract Classes
C# | String.IndexOf( ) Method | Set - 1
Different ways to sort an array in descending order in C#