简体   繁体   English

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

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

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

You use XML Documentation with 3 slashes (///)您使用带有 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)
   {
   }

Here you can find a tutorial on this type of documentation with a lot of examples. 在这里,您可以找到有关此类文档的教程,其中包含大量示例。

If you type three slashes in the line above your method ( /// ) it will expand to a template for XML documentation.如果您在方法 ( /// ) 上方的行中键入三个斜杠,它将扩展为 XML 文档的模板。 Anything you fill in the summary section will show up in the tooltip.您在summary部分填写的任何内容都将显示在工具提示中。

The template should look something like this (very simple example):模板应该是这样的(非常简单的例子):

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

In the line immediately Above the method enter three forward slashes /// and the template will appear auto-magically.在方法上方的行中输入三个正斜杠 /// 模板将自动出现。 Enter some text and it will be displayed.输入一些文本,它将显示出来。

To make the documentation a little bit easier you should take a look at GhostDoc .为了使文档更容易一些,您应该查看GhostDoc

Also if you built an assembly and like to use this somewhere else you should check in your Project Properties under Build the checkbox XML documentation file and always take care that this file will have the same name as your assembly and will stay in the same folder.此外,如果您构建了一个程序集并希望在其他地方使用它,您应该在构建复选框XML documentation file下检查您的项目属性,并始终注意该文件将与您的程序集具有相同的名称并保留在同一文件夹中。 Than these comments will also be used for IntelliSense when you added only a reference to the resulting assembly file.当您仅添加对生成的程序集文件的引用时,这些注释也将用于 IntelliSense。

Maybe this link also provides some useful informations for you.也许这个链接也为你提供了一些有用的信息。

For me, in the following manner too (in VS 2008):对我来说,也是以下方式(在 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