What are the comments in C#?


Comments are used for explaining code. Compilers ignore the comment entries. The multiline comments in C# programs start with /* and terminates with the characters */ as shown below.

Multi-line comments

/* The following is a mult-line
comment In C#
/*

The /*...*/ is ignored by the compiler and it is put to add comments in the program.

Single line comments

// variable
int a = 10;

The following is a sample C# program showing how to add single-line as well as multi-line comments −

Example

 Live Demo

using System;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         /* I have started learning C# and
         is my first program */

         // displaying text
         Console.WriteLine("Hello World");
         Console.ReadKey();
      }
   }
}

Output

Hello World

Updated on: 20-Jun-2020

120 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements