Hello World
Comments
Notice all the green text in the code below? Those are comments.
using System; public class Program { ...
Comments are a critical part of any program. They let you place free form text in your code. This is important so you can:
- Document what your code is doing
- Make notes of things to fix
- Document when changes are made and who made them
- Add documentation to be used by other development components
In C# there are several ways to add comments to code.
Single-line comments
You can comment out an entire line by placing // before the text you wish to be a comment.
//Console.WriteLine("Hello World");
Console.WriteLine("Hello World"); // This is a comment after some code.
Multi-line comments
Multi-line comments, or comment blocks are used to comment out any number of sequential lines. Everything between /* and */ becomes a comment.
/* This is a comment. So is this. And even this. */
Visual Studio and .NET Fiddle Shortcuts
In Visual Studio, you can comment and uncomment links of code using the toolbar.
Both Visual Studio and .NET Fiddle provide easy-to-use shortcuts for creating and removing comments:
Visual Studio | .NET Fiddle | |
---|---|---|
Comment Selected Line(s) | CTRL-K + CTRL-C | CTRL-Q |
Uncomment Selected Line(s) | CTRL-K + CTRL-U | CTRL-U |
Page 8 of 13