Comments
suggest changeUsing comments in your projects is a handy way of leaving explanations of your design choices, and should aim to make your (or someone else’s) life easier when maintaining or adding to the code.
There are two ways of adding a comment to your code.
Single line comments
Any text placed after // will be treated as a comment.
public class Program
{
// This is the entry point of my program.
public static void Main()
{
// Prints a message to the console. - This is a comment!
System.Console.WriteLine("Hello, World!");
// System.Console.WriteLine("Hello, World again!"); // You can even comment out code.
System.Console.ReadLine();
}
}
Multi line or delimited comments
Any text between /* and */ will be treated as a comment.
public class Program
{
public static void Main()
{
/*
This is a multi line comment
it will be ignored by the compiler.
*/
System.Console.WriteLine("Hello, World!");
// It's also possible to make an inline comment with /* */
// although it's rarely used in practice
System.Console.WriteLine(/* Inline comment */ "Hello, World!");
System.Console.ReadLine();
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents