Use code tag to reference code

   
 


// compile with: /doc:DocFileName.xml 

/// text for class TestClass
public class TestClass
{
    /// <summary><c>DoWork</c> is a method in the <c>TestClass</c> class.
    /// </summary>
    public static void DoWork(int Int1)
    {
    }

    /// text for Main
    static void Main()
    {
    }
}

   
     


Summary doc tag and paramref tag

   
 

// compile with: /doc:DocFileName.xml 

/// text for class TestClass
public class TestClass
{
    /// <summary>DoWork is a method in the TestClass class.  
    /// The <paramref name="Int1"/> parameter takes a number.
    /// </summary>
    public static void DoWork(int Int1)
    {
    }

    /// text for Main
    static void Main()
    {
    }
}

   
     


value doc tag

   
 

// compile with: /doc:DocFileName.xml 

/// text for class Employee
public class Employee
{
    private string _name;

    /// <summary>The Name property represents the employee&#039;s name.</summary>
    /// <value>The Name property gets/sets the _name data member.</value>
    public string Name
    {
        get
        {
            return _name;
        }
        set
        {
            _name = value;
        }
    }
}

/// text for class MainClass
public class MainClass
{
    /// text for Main
    static void Main()
    {
    }
}

   
     


Summary doc tag, example doc tag

   
 


// compile with: /doc:DocFileName.xml 

/// text for class TestClass
public class TestClass
{
    /// <summary>
    /// The GetZero method.
    /// </summary>
    /// <example> This sample shows how to call the <see cref="TestClass.GetZero"/> method.
    /// <code>
    /// class TestClass 
    /// {
    ///     static int Main() 
    ///     {
    ///         return GetZero();
    ///     }
    /// }
    /// </code>
    /// </example>
    public static int GetZero()
    {
        return 0;
    }

    /// text for Main
    static void Main()
    {
    }
}

   
     


XML based comments

   
  
using System;

/// <summary>
/// Main method.
/// <para>This sample is useless.</para>
/// </summary>
class SayHello {
    /// <summary>
    /// This is the Main method for the class and is
    /// the execution starting point for our application.
    /// Please note that <paramref name="args">args</paramref>
    /// is a array of strings.
    /// </summary>
    /// <param name="args">params for Main method</param>
    /// <returns>Returns a value depending on how the program
    /// was called.</returns>
    //We want Main to return an integer.
    public static int Main(string[] args) {
        if (args.Length > 0) {
            return (0);
        }
        return (1);
    }
}

   
     


How to write the Xml based document

   
  
using System;
using System.Collections.Generic;
using System.Text;

namespace XmlDocCar
{
    /// <summary>
    ///  This is a simple Car.
    /// </summary>
    public class Car
    {
        /// <summary>
        /// Do you have a sunroof?
        /// </summary>
        private bool hasSunroof = false;

        /// <summary>
        /// The ctor lets you set the sunroofedness.
        /// </summary>
        /// <param name="hasSunroof"></param>
        public Car(bool hasSunroof)
        {
            this.hasSunroof = hasSunroof;
        }

        /// <summary>
        /// This method allows you to open your sunroof.
        /// </summary>
        /// <param name="state"> </param>
        public void OpenSunroof(bool state)
        {
            if (state == true &amp;&amp; hasSunroof == true)
                Console.WriteLine("has sub roof!");
            else
                Console.WriteLine("you don&#039;t have a sunroof.");
        }
    }
}