This documentation is archived and is not being maintained.

cref Attribute (C# Programming Guide)

Updated: September 2008

The cref attribute in an XML documentation tag means "code reference." It specifies that the inner text of the tag is a code element, such as a type, method, or property. Documentation tools like Sandcastle use the cref attributes to automatically generate hyperlinks to the page where the type or member is documented.

The following example shows a cref attribute used in a <see> 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()

When compiled, the program produces the following XML file. Note that the cref attribute has been transformed by the compiler to "M:TestBedForWrap3.Wrap3.TestClass.GetZero". The "M:" prefix means "method" and is a convention that is recognized by documentation tools such as Sandcastle. For a complete list of prefixes, see Processing the XML File (C# Programming Guide).

<?xml version="1.0"?>
        <member name="T:TestBedForWrap3.Wrap3.TestClass">
            text for class TestClass
        <member name="M:TestBedForWrap3.Wrap3.TestClass.GetZero">
            The GetZero method.
            <example> This sample shows how to call the <see cref="M:TestBedForWrap3.Wrap3.TestClass.GetZero"/> method.
            class TestClass 
                static int Main() 
                    return GetZero();
        <member name="M:TestBedForWrap3.Wrap3.TestClass.Main">
            text for Main




September 2008

Added topic.

Customer feedback.