C# XML /// Comments, where does <returns></returns> tag show up?

17,025

Solution 1

When you see the method in View >> Object Browser

For e.g. you will see something like this:

private int GetColumnIndex(Microsoft.Office.Interop.Excel.Worksheet worksheet, string columnName, int rowIndex, int startColumnIndex)
    Member of MyAddIn.CommandHandlers.CommandHandler

Summary:
Returns the column index with specified name and in specified row

Parameters:
worksheet: Target worksheet
columnName: Column name to find
rowIndex: Row index in which to search the column
startColumnIndex: Start index of the column

Returns:
The index of column if found, else returns 0

Solution 2

If you generate API documentation from the comments, it will show up in the Return value section, as seen here, right before the Remarks section.

Solution 3

When you choose to build an XML documentation file on compilation, then everything that is contained in the XML documentation comments gets copied over into that file. Programs like Sandcastle then can build HTML documentation akin to the MSDN from that.

It doesn't show in Visual Studio's own IntelliSense, as far as I know. But that's no excuse not to write something there :-). ReSharper's Ctrl+Q for example does show it.

Solution 4

For those that may come trying to find something. This might not be the best approach but IMHO it does make more understandable what a method does while hovering over the method name.

        /// <summary>
        /// Adds a new post given the mapped PostDTO and userId <br></br><br></br>
        /// <b>Returns</b> the newly created object, otherwise null.
        /// </summary>
        /// <param name="postDTO"></param>
        /// <param name="userId"></param>
        PostDTO addPost(PostDTO postDTO, long userId);

This way you can see something in VS (at least in VS 2019) like in next image, which in my experience, when trying to understand code made by others, at least you can tell what to expect, whether an actual object or null, or whatever scenario.

enter image description here

I hope it may be useful for others.

Solution 5

The other sections (basically anything exception summary) won't appear in intellisense. They are only intended to appear in documentation generated from the XML, using a tool like Sandcastle.

Share:
17,025
Alex
Author by

Alex

I'm a web and mobile software engineer! Passionate about ruby and javascript.

Updated on June 05, 2022

Comments

  • Alex
    Alex almost 2 years

    I am currently a programming student, and obviously my question is simple, but I haven't been able to find the answer to it online. So here it is:

    In XML /// comments in C#, where does the <returns> tag show up, I know that everything contained in the <summary> tag shows up in intellisense when you hover your mouse over your method call, but not the returns tag.

    So where does the <returns> tag come in?

    Thanks.