How to add a line break in C# .NET documentation

C#.NetXml Documentation

C# Problem Overview


This should be waaaay easier...

I want to add a "coded" line break to the XML documentation in my code

/// <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 found some answers that demonstrated adding < and > brackets. Interestingly, the good 'ol < br/ > line break does not create a line break in the Intellisense popup.

I find this annoying...

Any suggestions?

C# Solutions


Solution 1 - C#

You can use a <para /> tag to produce a paragraph break or you can wrap text in <para></para> tags as a way to group the text and add the blank line after it, but there is no equivalent to <br /> or anything like that. (Which according to this old MS forum post is by design.) You can get the list of available tags in this documentation article from MS. Documenting your code

Example (based on original OP sample):

/// <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>

Solution 2 - C#

As of Visual Studio 2019, use <br/> for newlines in comments.

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>

enter image description here

Notice that there is no extra line added when we use <br/> instead of <para>.

Solution 3 - C#

This is my usage, like <br/> , it's working :)

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

Solution 4 - C#

Add a <para> tag with a special char in it, the 255 char, or invisible char.

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

It will work like this:

enter image description here

Solution 5 - C#

<br></br> and <br /> do not seem to work, and sometimes it isn't really about making the <para> sentences separate as much as the desire to have a blank line for concern separation. I am mentioning this here because this question seems to be to parent to many closed questions of this nature.

The only thing I found to work was

<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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTinkerer_CardTrackerView Question on Stackoverflow
Solution 1 - C#pstrjdsView Answer on Stackoverflow
Solution 2 - C#MahipalView Answer on Stackoverflow
Solution 3 - C#IlPADlIView Answer on Stackoverflow
Solution 4 - C#JoelView Answer on Stackoverflow
Solution 5 - C#Travis JView Answer on Stackoverflow