簡體   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