Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Most programming languages support comments: snippets of text that you can insert into your code that are meant for humans to read, not the computer. C# supports comments, too.
The first program we showed you included a line describing what part of the code does.
class Program
{
static void Main(string[] args)
{
// Displays "Hello World!" on the terminal.
System.Console.WriteLine("Hello World!");
}
}
Most programming languages support comments, snippets of text that you can insert into your code that are meant for humans to read, not the computer. C# supports comments, too.
- Let's suppose you have some code, and you think it won't be immediately obvious to other developers what it does.
- You can't just start typing an explanation. C# will think the text is part of your program, and try to run it, which won't work.
- Instead, you need to mark the text as something that shouldn't be run.
- If you insert two slashes (
//
) into your code, C# will ignore all the text from there to the end of the line. - You can do this on a line by itself.
- Or, you can do it at the end of a line of code.
// Comment
System.Console.WriteLine("Hello World!"); // Comment
You can use this to leave useful comments throughout your code. Anytime you write some code where the meaning isn't immediately obvious, you can add a comment that explains the code.
// Displays "Hello World!" on the terminal.
System.Console.WriteLine("Hello World!");
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up