Comments

Sometimes, you’ll want to leave some notes in your code, to help remind you later what the code does or why you wrote it a certain way. We can create a comment by using two forward slashes:

using System;

//Writes "Hello World" to the console
Console.WriteLine("Hello World!");

Comments won’t have any effect on the actual program when it runs - they’re purely for humans to read!

Block comments

You can also make a longer comment, by using a forward slash and an asterisk: /* followed by an asterisk and a forward slash: */

/*
First line of our program. We're using the console to write "Hello World"
None of this text matters because it's inside the comment block
Bla bla bla
bla bla bla
*/
Console.WriteLine("Hello World!");

“Commenting out” code

Sometimes you’ll hear programmers refer to “commenting out” code. That just means turning your code into a comment by putting the // in front of it. This can by handy if you want to disable part of your code, but keep it around for reference.

Example:

//this line is 'commented out'
//Console.WriteLine("Hello World!");

Previous submodule:
Next submodule: