CS Comments

As a programmer, a well documented program is a good practice. It makes a program easier to read and makes it easier to find errors. Comments are a major component of good documentation.

  • Computer programming is an explanation or an annotation readable by a programmer in the source code of a computer program
  • Comments are statements which the compiler and interpreter does not execute.

 

The comments in C # are statements that the compiler does not execute. The comment in C # can be used to explain the code, variable, method, or class. We can also hide the program code through comments.

Two comments in C # are available

  • Single Line comment
  • Multi Line comment

 

 

The comment for a single line begins on // (double slash). See an example of a single line comment in C#.

Example:


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

 

Output:

50

 

The C# multiline comment is used to comment various lines of code. Slash and asterisk are surrounded by it (/ * ..... *) We'll see a multi-line comment example in C#.


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

Output:

50