C Sharp Comments

C# Comments

The statements that the compiler does not execute are called the Comments in C#. It is mostly used to give a short explanation of a part of the code or for a variable, a method or a class. It is also sometimes used to hide the program code. In C#, we can use either of the two types of comments.

  • Single Line comment
  • Multi-Line comment

C# Single Line Comment:

To comment a single line of code, the single-line comment is used in C#, which starts with a double slash ( // ).

Example:

using System;  
   public class Example  
    {  
       public static void Main(string[] args)  
        {  
            char ch = 'a'; //Here, ch is a character    
            Console.WriteLine(ch);  
        }  
    }

Output:

a

Explanation:

In the above example, we are displaying the use of the single-line comment in C#.

C# Multi-Line Comment:

To comment the multiple lines of code, the multi-line comment is used in C#, which starts and ends with a slash and asterisk (/* ….. */).

Example:

using System;  
   public class Example  
    {  
       public static void Main(string[] args)  
        {  
		   /* Here we are declaring and  
          printing a character in C#. */   
            char ch = 'a';   
            Console.WriteLine(ch);  
        }  
    }

Output:

a

Explanation:

In the above example, we are displaying the use of the multi-line comment in C#.