Comments

There are three styles of comments we can use in C# code.

Single line comments

A single line comments start with // and continues until the end of line.


using System;

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);
    }
}

Multiple line comments

C# multiple line comments start with /* and end with */.


using System;

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);
    }
}

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;

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);
    }
}
  
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.