How to write single-line comments in C#?


If you want to add a comment that restricts itself to a single line, then use the single-line comments −

// variable
int i = 20;

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

Example

 Live Demo

using System;

namespace Demo {
   class Program {
      static void Main(string[] args) {

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

Output

Hello World

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

130 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements