'Can I add links in comments to a code block in Visual studio?

Can I add links in comments to a code block in Visual studio ?

For example:

// block 1
class class1
{
}

// block 2
class class2
{
    // review [___class1]
}

[___class1] is a link for class1

Thanks in advance.



Solution 1:[1]

It depends what you want - you can just add a URL and VS will turn it into a link automatically within the code view.

Whether this is translated into a link when you generate the documentation will depend on what tool you use for that.

EDIT: Okay, it's possible that I missed your meaning. It's not terribly clear exactly what you're trying to do.

If you want to provide some example code, you can use the example tag:

/// <example>
/// Foo f = new Foo();
/// </example>

Is that what you meant?

You can't link to a particular block of code, but you can link to a member or type, for example:

/// <remarks>
/// You can use the <see cref="DoSomething" /> method to do something similar.
/// </remarks>

Solution 2:[2]

You can always put links in comments (since they are simply text, like the rest of the file).

It depends on the IDE how these will be displayed - Visual Studio will make it a clickable hyperlink.

Edit:

If you want to reference other sections of your code from comments, there is no current support in visual studio for this. The closest you can get is with code documentation comments using a referntial tag such as see, this will still not produce a hyperlink in the IDE.

Solution 3:[3]

If you're looking for JS/TS support, as of May 2021, VS Code added support for standard JsDoc tagging:

https://code.visualstudio.com/updates/v1_57#_jsdoc-link-support

So that now this works:

{@link MyClassName}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jon Skeet
Solution 2 Oded
Solution 3 chrismarx