How to write comments / documentation for variables / fields / lists in VS 2010?

人盡茶涼 提交于 2019-12-18 02:14:12

问题


There is

///<summary>
///This is summary for some class or method
///</summary>

documentation for classes or methods. But how to write this for simple variables or lists?

I use Visual Studio 2010 and when i hover over some list, property or what ever i would like to see some kind of summary (in that little tooltip) i have written to that specific thing.

///<doc>
///always use this list!
List<String> beer = new List<String>();

edit: ok, we have found out, that it works as usual as long u comment in your class but OUTSIDE a method or a function!!

Any way to document/comment within a method too?

public class BeerForall
{
    /// <summary>
    /// it works here
    /// </summary>
    public List<String> beer = new List<string>();

    public String giveBeer()
    {
        /// is not working, u can not comment
        /// <summary>
        /// test test, not working
        /// </summary>
        List<String> moreBeer = new List<string>();

        return "beer";
    }
}

回答1:


Seems to work perfectly fine in Visual Studio 2010. I defined a List as a private field with a comment inside my MainForm class.

They won't work for local variables defined within functions though.




回答2:


As others mentioned, you can't get IntelliSense for local vars. However: If your function is so large that a "regular" comment is not close enough to read near the place where you're using the var, then the right fix is to refactor the function -- break it up into multiple, smaller methods, with fewer vars. I don't think this feature should exist, as it would serve only to facilitate writing excessively large functions.




回答3:


As far as I know, adding comments for intellisense will not work for local variables declared within functions. If you were to make your local list an instance variable of the class, you would be able to do this.




回答4:


The same way as you write summary for classes and methods work for variables.




回答5:


You can add such XML documentation comments to any class member, not inside a member (method, property, etc).




回答6:


Edit: it looks like <var> is only supported for JavaScript.

As of Visual Studio 2012 you can add this documentation using the <var> element.

Here's Microsoft's documentation on it:
https://msdn.microsoft.com/en-us/library/hh542722(v=vs.110).aspx



来源:https://stackoverflow.com/questions/7954029/how-to-write-comments-documentation-for-variables-fields-lists-in-vs-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!