Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 method?

like image 378
murtek Avatar asked Nov 04 '10 08:11

murtek


People also ask

How do I comment a method in Visual Studio?

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.

How do you comment a whole method in C#?

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.

How do you comment out code in Visual Basic?

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.

How do I add a comment to a method in Visual Studio?

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.

What types of comments are not available in Visual Studio Code?

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.

How do I comment multiple lines at once in Visual Studio?

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.

How do I add comments to an XML file?

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.


2 Answers

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.

like image 52
Liviu Mandras Avatar answered Sep 29 '22 08:09

Liviu Mandras


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; } 
like image 31
Colin Pickard Avatar answered Sep 29 '22 09:09

Colin Pickard