Coder Perfect

In C#.NET documentation, how do you add a line break?

Problem

This should be a piece of cake…

In my code, I’d like to add a “coded” line break to the XML description.

/// <summary>
/// Get a human-readable variant of the SQL WHERE statement of the search element. &lt;br/&gt;
/// Rather than return SQL, this method returns a string with icon-tokens, which 
/// could be used to represent the search in a condensed pictogram format.
/// </summary>

As you can see, I discovered a few replies that showed how to use the and > brackets. In the Intellisense popup, the good ‘ol br/ > line break does not produce a line break.

This irritates me.

Any suggestions?

Asked by Tinkerer_CardTracker

Solution #1

You can create a paragraph break by using the para /> tag, or you can wrap text in the para>/para> tags to group the text and add the blank line after it, but there is no equivalent to the br /> element. (Which is by design, according to this old MS forum post.) The list of accessible tags can be found in this MS documentation item. Keeping track of your code

Using the original OP sample as an example:

/// <summary>
/// <para>Get a human-readable variant of the SQL WHERE statement of the search element.</para>
/// Rather than return SQL, this method returns a string with icon-tokens, which 
/// could be used to represent the search in a condensed pictogram format.
/// </summary>

Answered by pstrjds

Solution #2

Use br/> for newlines in comments as of Visual Studio 2019.

Example:

/// <summary>
/// This is a comment.<br/>
/// This is another comment <br/>
/// This is a long comment so i want it to continue <br/> on another line.
/// </summary>

When we use br/> instead of para>, there is no additional line added.

Answered by Mahipal

Solution #3

This is how I use it, and it works for me:)

/// <summary>
/// Value: 0/1/2
/// <para/>0 foo,
/// <para/>1 bar,
/// <para/>2 other
/// </summary>

Answered by IlPADlI

Solution #4

Create a para> tag with a special char, the 255 char, often known as the invisible char.

/// <summary>
/// Some text
/// <para> &nbsp; </para>
/// More text
/// </summary>
/// <param name="str">Some string</param>
public void SomeMethod(string str) { }

This is how it will work:

Answered by Joel

Solution #5

br>/br> and br /> don’t appear to work, and sometimes the urge to have a blank line for worry separation is more important than having the para> phrases separate. This is something I’m bringing up because this question appears to be the father of a lot of similar closed questions.

I only found one thing that worked for me.

<para>&#160;</para>

For example

/// <summary>
///     <para>
///         "This sentence shows up when the type is hovered"
///     </para>
///     <para>&#160;</para>
///     <para>int PrimaryKey</para>
///     <para>&#160;</para>
///     <para>virtual Relation Relation</para>
/// </summary>

Results in

"This sentence shows up when the type is hovered"

int PrimaryKey

virtual Relation Relation

Answered by Travis J

Post is based on https://stackoverflow.com/questions/7279108/how-to-add-a-line-break-in-c-sharp-net-documentation