Xml Documentation

In this chapter you will learn:

  1. How to write Standard Xml documentation tags
  2. Standard Xml documentation tags
  3. Documentation Comments for a method with parameters
  4. see also and reference

Xml Documentation

You can use predefined Xml tag to mark comments. Then we use C# compiler with /doc option to generate Xml documentation for the source code.

Xml documentation should be put inside ///.

/// <summary>a method.</summary>
public void aMethod() { ... }

Standard Xml documentation tags

<summary>...</summary>                        A single phrase or sentence summary.
<remarks>...</remarks>                        Additional text that describes the type or member.
<param name="name">...</param>                Explains a parameter on a method.
<returns>...</returns>                        Explains the return value for a method.
<exception [cref="type"]>...</exception>      Lists an exception that a method may throw.
<permission [cref="type"]>...</permission>    Indicates an IPermission type required by the documented  type or member.
<example>...</example>                        Denotes an example.
<c>...</c>                                    Indicates an inline code snippet.
<code>...</code>                              Indicates a multiline code sample.
<see cref="member">...</see>                  Inserts an inline cross-reference to another type or member.
<seealso cref="member">...</seealso>          Cross-references another type or member.
<paramref name="name"/>                          References a parameter from within a <summary> or <remarks> tag.
<list type=[ bullet | number | table ]>          Instructs documentation generators to emit a bulleted, numbered, or table-style list.
  <listheader>/*  j  a  va  2s. co m*/
    <term>...</term>
    <description>...</description>
  </listheader>
  <item>
        <term>...</term>
       <description>...</description>
  </item>
</list>
<para>...</para>                                 Format  the  contents  into  a  separate paragraph.
<include>                                        Merges an external XML file that contains documentation.

Documentation Comments for a method with parameters

using System;// j ava  2s  .c o  m

namespace DocumentationCommentsExample
{
    /// <summary>
    /// A documentation sample - the short description goes here
    /// </summary>
    /// <remarks>Where a longer description would go</remarks>
    class ClassExample
    {
        /// <summary>
        /// A member variable
        /// </summary>
        private string m_str;


        /// <summary>
        /// A method example
        /// </summary>
        /// <param name="val">a new value to be saved</param>
        /// <returns>the length of the string</returns>
        public int MethodExample( string val )
        {
            m_str = val;
            return val.Length;
        }

    }
}

see also and reference

using System;// j a va2s. c  om

namespace Payroll
{
    
    /// <summary> 
    /// Document for Employee class
    /// See a cross reference <see cref="String">string</see>
    /// </summary>
    public class Employee
    {
        /// <summary>
        /// Comment for the constructor
        /// <paramref name="name">name2</paramref> is a string.
        /// </summary>
        /// <param name="id">Employee id number</param>
        /// <param name="name">Employee Name</param>
        public Employee(int id, string name)
        {
            this.id = id;
            this.name = name;
        }
        
        /// <summary>
        /// Comments for another constructor
        /// </summary>
        /// <remarks>
        /// <seealso cref="Employee(int, string)">Employee(int, string)</seealso>
        /// </remarks>
        public Employee()
        {
            id = -1;
            name = null;
        }
        int id;
        string name;
    }
}

Next chapter...

What you will learn in the next chapter:

  1. What are the C# operators
  2. Operators and its categories
Home » C# Tutorial » Statements
Comments
if Statement
while loop
do...while loop
for loop
foreach
switch
break
continue statement
goto statement
Xml Documentation