C# Comments

 The C# comments are statements that are not executed by the compiler. The comments in C# programming can be used to provide explanation of the code, variable, method or class. By the help of comments, you can hide the program code also.

There are two types of comments in C#.

  • Single Line comment
  • Multi Line comment

C# Single Line Comment

The single line comment starts with // (double slash). Let's see an example of single line comment in C#.

  1. using System;  
  2.    public class CommentExample  
  3.     {  
  4.        public static void Main(string[] args)  
  5.         {  
  6.             int x = 10;//Here, x is a variable    
  7.             Console.WriteLine(x);  
  8.         }  
  9.     }  

Output:

10

C# Multi Line Comment

The C# multi line comment is used to comment multiple lines of code. It is surrounded by slash and asterisk (/* ..... */). Let's see an example of multi line comment in C#.

  1. using System;  
  2.    public class CommentExample  
  3.     {  
  4.        public static void Main(string[] args)  
  5.         {  
  6.             /* Let's declare and  
  7.           print variable in C#. */   
  8.             int x=20;  
  9.             Console.WriteLine(x);  
  10.         }  
  11.     }  

Output:

20

Comments

Popular posts from this blog

C# | Association, Aggregation and Composition

Throw vs Throw ex in C#

String[] args in C#