开发者

How to comment a method in Visual Studio 2008/2010

How must I comment a method in Visual Studio so that I can see my description in the tooltip when I want to select the meth开发者_StackOverflow中文版od?


You use XML Documentation with 3 slashes (///)

   /// <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. Anything you fill in the summary section will show up in the tooltip.

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.

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. Than these comments will also be used for IntelliSense when you added only a reference to the resulting assembly file.

Maybe this link also provides some useful informations for you.


For me, in the following manner too (in 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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜