Comments are that block of code that is used for program documentation and those line(s) of code is ignored  by compiler while execution.

There are three ways of commenting in C#.

  1. Single Line Comment
  2. MultiLine Comment
  3. XML documentation comment

Comments in C#

1. Single Line Comment in C#:

When you just want to comment of only a single line and not more.  For single line comment use “// “.
Ex :


Here the “world” will get printed but hello will not printed as you have by commenting asked the compiler to avoid that particular line.

2. MultiLine Comment in C#:

If you want to comment more than single line of code, you should put the lines between /* …           ….*/.

   /* Console.WriteLine(“Hello”);
      Console.WriteLine(“World”);  */

Now in this case, nothing will be printed.

3. XML documentation Comment in C#:

Use /// to get the XML documentation of visual studio to detect it. There is more to it but not currently in scope of this article.