C#

C# Comments

Comments are only for you to read, not for the computer to execute. All the comments displayed in the Code Editor are green by default, which makes it easy to identify those lines, and the C# compiler ignores those parts when it runs your program.

Single-line comments

You can make any line into a single-line comment by starting it with the two forward slash marks //, indicating that the remainder of the line is a comment.

//This is comment
Console.WriteLine("This is not a comment");

Run Demo

// int age = 35;
Console.WriteLine(age);

Compiler ignored first line of code and used it as a comment.

Run Demo

End-of-line comments

Everything before // is a normal line of code and everything after that is a comment.

int variableName = 1;  //this is comment

Run Demo

Multiline comments ( Delimited comments )

Multiline comment begins with an open comment mark /* and ends with a closed comment mark */. All the text between the delimiters is ignored by the compiler.

/*
Comment Line 1
Comment Line 2
Comment Line 3
*/

/*********************
* Comment Line 1
* Comment Line 2
* Comment Line 3
**********************/

Run Demo

Pirzada Rashid

Senior .NET developer with a Master of Science in Information Technology.
Teaching is one of my passions. It gives me great joy to share my knowledge with others, and I look forward to investing more energy into it.

Add Comment

Click here to post a comment

Most Popular

Popular Video

82,490+ Views