Comments
Swipe to show menu
In programming, comments are parts of code meant for leaving notes or messages for yourself or other developers. A comment does not affect the functionality of the program.
A single-line comment can be added using the double forward slash (//) operator:
main.cs
1234567891011namespace TestConsoleApp { internal class Program { static void Main(string[] args) { // This is a comment System.Console.WriteLine("Hello World"); } } }
A multi-line comment can be added by enclosing the text inside /* and */ operators.
main.cs
1234567891011121314151617namespace TestConsoleApp { internal class Program { static void Main(string[] args) { /* This is a multi-line comment */ System.Console.WriteLine("Hello World"); } } }
Multi-line comments can also be used to comment out parts of a single line:
main.cs
1234567891011namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine(/*" This text will not be shown." */ "This text will be shown. "); /* System.Console.WriteLine("The whole statement is commented out"); */ } } }
It is also a common practice to comment-out a piece of code which we temporarily want to exclude from the program:
main.cs
12345678910111213namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Line 1"); System.Console.WriteLine("Line 2"); // System.Console.WriteLine("Line 3"); System.Console.WriteLine("Line 4"); } } }
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 5
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Section 1. Chapter 5