繁体   English   中英

如何在 Visual Studio 2008/2010 中注释方法

[英]How to comment a method in Visual Studio 2008/2010

我必须如何在 Visual Studio 中注释方法,以便在我想选择方法时可以在工具提示中看到我的描述?

您使用带有 3 个斜杠 (///) 的 XML 文档

   /// <summary>
   /// Description for SomeMethod.</summary>
   /// <param name="s"> Parameter description for s goes here</param>
   /// <seealso cref="String">
   /// You can use the cref attribute on any tag to reference a type or member 
   /// and the compiler will check that the reference exists. </seealso>
   public void SomeMethod(string s)
   {
   }

在这里,您可以找到有关此类文档的教程,其中包含大量示例。

如果您在方法 ( /// ) 上方的行中键入三个斜杠,它将扩展为 XML 文档的模板。 您在summary部分填写的任何内容都将显示在工具提示中。

模板应该是这样的(非常简单的例子):

/// <summary>
/// Always returns 1
/// </summary>
private Int32 MyMethod()
{
    return 1;
}

在方法上方的行中输入三个正斜杠 /// 模板将自动出现。 输入一些文本,它将显示出来。

为了使文档更容易一些,您应该查看GhostDoc

此外,如果您构建了一个程序集并希望在其他地方使用它,您应该在构建复选框XML documentation file下检查您的项目属性,并始终注意该文件将与您的程序集具有相同的名称并保留在同一文件夹中。 当您仅添加对生成的程序集文件的引用时,这些注释也将用于 IntelliSense。

也许这个链接也为你提供了一些有用的信息。

对我来说,也是以下方式(在 VS 2008 中):

void foo
(int x)
/*
Function description here
*/
{

}
    /// <calculate volume>
    /// 
    /// </volume>
    /// <lenght lenght="num1"></toconvert>
    /// <width width="num2"></convert>
    /// <hight height="num3"></volume>
    public static void VolBox(int num1, int num2,int  num3)
    {
        //looks for imput tofind volume of rectangular box
        int volume;
        volume = num1 * num2 * num3;
        Console.WriteLine("the volume of your rectangle box is {0} .",volume);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM