文档注释是为了方便自己和他人更好地理解代码所实现的功能。下面记录了一些常用的文档注释标记:
<C>
用法: <c>text</c>
将说明中的文本标记为代码。例如:
/// <summary> /// Validates the user. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns>
/// <c>true</c>, if username and password are equal. /// </returns> public bool ValidateUser(string username, string password) { var userId = GetUserIdIfValid(username, password); return userId.HasValue && userId.Value != Guid.Empty; }
<code>
用法: <code>content</code>
将多行文本标记为代码。
<see>
用法: <see cref="member"/>
用于从文本中指定链接。例如:
/// <summary> /// Initializes a new instance of the <see cref="DefaultAuthenticationService" /> class. /// </summary> /// <param name="repository">The repository.</param> public DefaultAuthenticationService(IRepository repository) { this.repository = repository; }
<example>
用法: <example>description</example>
用于指定使用方法或其他库成员的示例。例如:
/// <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; }