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

Single Line Comment

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

Example
snippet
using System;
   public class CommentExample
    {
       public static void Main(string[] args)
        {
            int x = 10;//Here, x is a variable  
            Console.WriteLine(x);
        }
    }
Output
10

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#.

Example
snippet
using System;
   public class CommentExample
    {
       public static void Main(string[] args)
        {
            /* Let's declare and 
		  print variable in C#. */ 
	        int x=20;
            Console.WriteLine(x);
        }
    }
Output
20
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +