Developers often need to collaborate with other developers. Comments are an easy way for developers to write notes in the code and communicate with others. Comments are ignored by the computer; thus, they are also an easy way to tell the computer to not run certain lines of code. There are two ways to create comments:
- To comment out one line, place
//in front of a line of code. For example:
// This is a single-line comment.
- To comment out multiple lines at once, indicate the start of the comment with
/*and the end of the comment with
*/. For example:
/* This is a multi-line comment. This line is also part of the comment. */
To remove a comment (or uncomment a line), simply delete the
// for a single-line comment, or the
/* and the
*/ characters for the multi-line comment.
//in front of
Console.WriteLine("Hello World");. After pressing run, check to make sure that
Hello Worldis not printed to the console.
- Delete the
//and instead, surround
*/. Check that
Hello Worldis still not printed to the console after pressing run.
- Delete both
*/, and press run.
Hello Worldshould now be printed to the console.
Throughout today’s activity you will see various multi-line comments and
// TODO comments. These comments will guide us towards completing the Guess the Word game, so be sure you understand how to comment and uncomment code.