148

Greetings

When setting a summary for a property / field / method etc.. is it possible to have a newline in it?

/// <summary>
/// This is line 1
/// This is line 2
/// </summary>
public bool TestLine { get; set; }

When I set this it shows as on mouse over:

bool TestLine
This is line 1 This is line 2

But I want it to show as:

bool TestLine
This is line 1 
This is line 2

I've tried using \n but that doesn't work. Is there any way to get this done?

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
Theun Arbeider
  • 5,259
  • 11
  • 45
  • 68

9 Answers9

249

You want to use some thing like this

/// <summary> 
/// Your Main comment 
/// <para>This is line 1</para> 
/// <para>This is line 2</para> 
/// </summary> 
public bool TestLine { get; set; }
YetAnotherUser
  • 9,156
  • 3
  • 39
  • 53
  • 1
    @YetAnotherUser, what about a blank line? – Behzad May 06 '13 at 18:18
  • 1
    @Behzad try using ` `. – YetAnotherUser May 06 '13 at 20:17
  • 19
    In the Visual Studio 2017 IDE, the above "solution" actually displays a lone BLANK LINE between line 1 and line 2 (that is, a newline after line 1 followed by a blank line then line 2)--this is not the same a new line, as the OP requested. Is that a bug in the VS 2017 IDE--or does everyone who up-voted not see that this answer doesn't produce what the OP shows as the desired output? – Jazimov Feb 02 '18 at 00:42
  • 1
    That's a new paragraph, not a new line. It feels to me that the documentation syntax is somewhat limiting. – GrizzlyMcBear Jul 17 '19 at 06:33
74

This may be an old thread but I was searching for an anwser while using Visual Studio 2019. I wanted paragraph and lines breaks. The following works well for me:

/// <summary>
/// <para>parameter name="guidType" options:</para>
/// <br>0 = SequentialAsString</br>
/// <br>1 = SequentialAsBinary</br>
/// <br>2 = SequentialAtEnd</br>
/// </summary>

Produces the following:

parameter name="guidType" options:

0 = SequentialAsString
1 = SequentialAsBinary
2 = SequentialAtEnd
Thomas Cayne
  • 1,132
  • 8
  • 15
34

Yes:

/// <summary> 
/// Main comment 
/// <para>Line 1</para> 
/// <para>Line 2</para> 
/// </summary> 
public bool TestLine { get; set; }
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
16

You can use <para /> to add a new line within summary:

/// <summary> 
/// Main comment<para />
/// Line 1<para />
/// Line 2<para />
/// </summary>
public bool TestLine { get; set; }

Looks like:

Main comment
Line 1
Line 2

Best regards!

fdelgado
  • 169
  • 1
  • 3
11

I would suggest using this formatting if you want multiple lines in the summary without making it complicated. It'll work if you use the <br /> tag after each line. (using it anywhere inside the text will make a new line where the tag is also.)

Although, note that if you have a space after the <br /> tag, you would get an extra space one the next line. So you wanna have the same amount of space on each line, so every row it'll be in a straight line.

/// <summary>
/// This is line 1<br />
/// This is line 2<br />
/// This is line 3<br />
/// </summary>
public bool TestLine { get; set; }
Jonathan
  • 311
  • 2
  • 3
8

You can legitimately add para tags, but this actually creates a new paragraph for each new line and the line spacing appears off.
I personally add 1 para around the paragraph and then br tags at the end of the lines I wanted a break on, which preserves decent line spacing:

/// <summary> 
/// <para>Main comment<br /> 
/// Line 1<br />
/// Line 2</para> 
/// </summary>
public bool TestLine { get; set; }
Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
PDizzle
  • 151
  • 2
  • 6
2

I'm just adding this for anyone using Xamarin Studio like I am. I found that none of the above solutions work for me, but this one did:

/// <summary>
/// Main summarry line.
/// <para></para>
/// <para></para>
/// Your secondary summary
/// </summary>

This gives the following output:

Summary  
Main summary line.

Your secondary summary
head in the codes
  • 1,159
  • 12
  • 24
1

If you are using Swashbuckle (Swagger Web API integration library) then <para></para> should be replaced with <p></p> and <br/> also could be used.

so the following

    /// <para>
    ///     Flag1, Flag2
    ///     - bool flags, optional.
    /// </para>

becomes

    /// <p>
    ///     Flag1, Flag2<br/>
    ///     - bool flags, optional.
    /// </p>

The issue is already described here: How to add line break to Swashbuckle documentation? - using a special config, domaindrivendev's comment, https://github.com/domaindrivendev/Swashbuckle/issues/258 - on <br/> usage.

Dmitry Karpenko
  • 544
  • 5
  • 6
0

Something I didn't see elsewhere in this thread is that there is a difference between <para></para> and <br></br>.

<para> will add a second newline above the text. So you'll end up with text>empty newline>text.

<br> will only add a single newline. So you'll end up with text>text.

So, IMO, br is better for lists and para is better for breaking up lines.

sermer
  • 1