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 method?
Place your text cursor above the element you want to document, for example, a method. Do one of the following: Type /// in C#, or ''' in Visual Basic. From the Edit menu, choose IntelliSense > Insert Comment.
A comment is preceded by an double forward slash. The code of line after the double forward slash is simply ignored by the compiler. To code a comment, type an double forward slash followed by the comment. You can use this technique to add a comment on its own line or to add a comment after the code on a line.
In VB . NET, you write a comment by writing an apostrophe ' or writing REM . This means the rest of the line will not be taken into account by the compiler.
It’s fairly easy to place a comment on a single method with Visual Studio. Just type /// ( ”’ for VB) above the method, property, or class, and Visual Studio puts a template-based XML comment block in there for you! All you have to do is fill in some details.
Other types of comments include work item comments, which aren’t really accessible in VS. Let’s consider that your consumers—developers—are under pressure to deliver. They’re using some code you created and packaged for their consumption. This code is built to make your consumers more productive.
Usually, you’d use a multi-line comment in cases like this. Unfortunately, Visual Studio will only lay down several single-line comments instead. Here’s a trick for commenting multiple lines at once with a space, though. First, get out your Alt key and hold that guy down while you use the cursor to “box select” the columns to the left of your code.
To insert XML comments for a code element Place your text cursor above the element you want to document, for example, a method. Do one of the following: Type /// in C#, or ''' in Visual Basic Enter descriptions for each XML element to fully document the code element.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With