C# Comments
In this chapter you will learn:
- What are C# comments
- What are the three types of comments
- Single line comments
- Multiple line comments
- XML documentation comments
Description
We use comments to explain the meaning of statements in C# code.
Three types of comments in C#
There are three styles of comments we can use in C# code.
- Single line comments
- Multiple line comments
- XML documentation comments
Single line comments
A single line comments start with //
and continues until the end of line.
using System;//w ww .j a va 2 s . c o m
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 2;
//This is a single line comment.
Console.WriteLine("i=" + i);
Console.WriteLine("j=" + j);
}
}
The code above generates the following result.
Multiple line comments
C# multiple line comments start with /*
and end with */
.
using System;//from w w w . ja va2s.co m
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 2;
/*
This is a multi-line comment.
*/
Console.WriteLine("i=" + i);
Console.WriteLine("j=" + j);
}
}
The code above generates the following result.
XML documentation comments
The third type of comments is XML documentation comment. In the C# source code, the comments may contain XML tags. Those tags mark the comments to provide information for the code.
using System;//from w ww. j a v a 2 s .co m
class Program
{
/// <summary>
/// This the XML documentation.
/// </summary>
static void Main(string[] args)
{
int i = 0;
int j = 2;
Console.WriteLine("i=" + i);
Console.WriteLine("j=" + j);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- What is if statement
- How to create if statement
- Example for simple if statement
- Combine else if clauses to test for multiple conditions
- Nested if statement