C# Comments
A comment is a piece of text within a program that is not executed. It can be used to provide additional information to aid in understanding the code.
Single-line Comments
For single-line comments, the compiler ignores any text after two consecutive forward slashes (//) on the same line.
// Comment goes hereexecuting code // Comment goes here
Multi-line Comments
Multi-line comments begin with /* and end with */. The compiler ignores any text in between.
/*This is all commented out.None of it is going to run!*/
Example
The following examples show various comment styles:
// This line will denote a comment in C-sharp.Console.WriteLine("Hello World!"); // This is a comment./*This is a multi-linecomment.*/
XML Comments
XML comments are structured comments that produce API documentation. The C# compiler produces an XML file that contains structured data representing the comments. Other tools can process that XML output to create human-readable documentation in the form of web pages or PDF files, for example.
Syntax
The following is a single-line XML comment, which uses three forward slashes (///):
/// XML Comment goes here
Multi-line XML comments are similar to regular multi-line comments, except that an extra asterisk * is used in the opening:
/**XML Comments go here*/
Example
XML tags embedded in XML comments are used to signal a specific functionality of the XML comment to the compiler. The <summary> tag in the following example describes a type or a member, in this case, the public class MyClass:
/// <summary>/// This class performs an important function./// </summary>public class MyClass {}
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
- Beginner Friendly.15 hours