<example>(C# 编程指南)

<example>description</example>

参数

  • description
    代码示例的说明。

备注

使用 <example> 标记可以指定使用方法或其他库成员的示例。 这通常涉及使用 <code> 标记。

使用 /doc 进行编译可以将文档注释处理到文件中。

示例

// Save this file as CRefTest.cs 
// Compile with: csc CRefTest.cs /doc:Results.xml  

namespace TestNamespace
{
    /// <summary> 
    /// TestClass contains several cref examples. 
    /// </summary> 
    public class TestClass
    {
        /// <summary> 
        /// This sample shows how to specify the <see cref="TestClass"/> constructor as a cref attribute.�
        /// </summary> 
        public TestClass()
        { }

        /// <summary> 
        /// This sample shows how to specify the <see cref="TestClass(int)"/> constructor as a cref attribute.�
        /// </summary> 
        public TestClass(int value)
        { }

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

        /// <summary> 
        /// The GetGenericValue method. 
        /// </summary> 
        /// <remarks>  
        /// This sample shows how to specify the <see cref="GetGenericValue"/> method as a cref attribute.
        /// </remarks> 

        public static T GetGenericValue<T>(T para)
        {
            return para;
        }
    }

    /// <summary> 
    /// GenericClass. 
    /// </summary> 
    /// <remarks>  
    /// This example shows how to specify the <see cref="GenericClass{T}"/> type as a cref attribute.
    /// </remarks> 
    class GenericClass<T>
    {
        // Fields and members.
    }

    class Program
    {
        static int Main()
        {
            return TestClass.GetZero();
        }
    }
}

请参见

参考

建议的文档注释标记(C# 编程指南)

概念

C# 编程指南