Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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";
    }
}
like image 987
Gero Avatar asked Oct 31 '11 12:10

Gero


People also ask

How do you write a summary comment in C#?

The first rule for commenting is it should have /// three slash for comments as C# supports C++ style commenting so commenting can be done by // -- two slashes -- but for Documentation /// is necessary. We will go through each one by one. You can add a paragraph to the description by using <para> tag.

How do you insert comments in C# code?

Single-line comments start with two forward slashes ( // ). Any text between // and the end of the line is ignored by C# (will not be executed).


3 Answers

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.

like image 50
Craig Stuntz Avatar answered Oct 30 '22 09:10

Craig Stuntz


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.

enter image description here

like image 43
gideon Avatar answered Oct 30 '22 10:10

gideon


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.

like image 29
ooPeanutButter Avatar answered Oct 30 '22 10:10

ooPeanutButter