Introduction: C# Comments

In this post, we will learn about C# Comments C#.Net with an example.

Description:

In my previous posts I have explained various topics likeĀ Disable right click on web page and images, Nullables in C# Collections in C#SortedSet in C#.Net,Stack in C#,Queue in C#.Net,LinkedList in C#.Net. Now in this post, I will explain aboutĀ C# Comments with appropriate example.

The C# comments are statements or lines of code that are not executed by the compiler. The comments in C# programming are used to provide explanation of the code, variable, method, logic of codes or class.

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

using System;  
   public class CommentDemo  
    {  
       public static void Main(string[] args)  
        {  
            int _max = 15;//Here,is max variable 
            Console.WriteLine(x);  
            Console.ReadLine();
        }  
    }  

C# Multi Line Comment

The C# multi line comment is used to comment more than one line of code. It is surrounded by slash and asterisk (/* ….. */). Let’s see an example of multi line comment in C#.

using System;  
   public class CommentExample  
    {  
       public static void Main(string[] args)  
        {  
            /* Let's declare and  
          print variable in C#. This is multi line comment */   
            int x=20;  
            Console.WriteLine(x);  
        }  
    }  

Summary

I hope you got an idea about C# Comments.
I would like to have feedback from my blog readers.
I hope after reading this article you will be able to do this.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website