dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.23k stars 5.87k forks source link

Clarifications regarding two of the listed string literal rules #34192

Open burnchar opened 1 year ago

burnchar commented 1 year ago

I believe this document is good overall but can use a few clarifications:

Both opening and closing quote characters must be on their own line. Whitespace only lines following the opening quote are included in the string literal.

What does "On their own line" mean? The code example immediately preceding this rule begins with: var xml = """ Are those quotes "on their own line" despite being on the same line as the variable declaration? Either way, is the whitespace that follows that initial line included in the string literal?

var xml = """  // Is this whitespace included in the string literal? This is a "whitespace only line"
        <element attr="content">
            <body>
            </body>
        </element>
        """;

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

BillWagner commented 1 year ago

Good questions @burnchar

We should fix this language on multi-line raw string literals.

The opening """ must be the last non-whitespace character on that line. (The example in your description won't compile See Sharplab.io

Any whitespace following the """ on the line opening the raw string literal is ignored.

I've added this to our backlog to update this on our next update. I've also added the "help wanted" label if anyone wants to submit a PR in the meantime.