-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Proposed topic or title
Language Syntax in Raw String Literals
Location in table of contents.
No response
Reason for the article
This is a neat feature that seems very useful, but is completely undocumented. I only know about it from a post on Reddit that I read.
Article abstract
To enhance your code-writing experience, you can include //lang={language} to allow your IDE to highlight your Raw String Literals in the format of your language of choice. What this means is, if you include a comment above your Raw String Literal, and it matches the format specified, you get custom language highlighting.
e.g.:
public class MyExample {
//lang=json
public static readonly string JsonString = """
{
"statusCode": 400,
"error": "Bad Request",
"message": "The request was invalid."
}
""";
}
Seems to result in the quotes text appearing like:

Relevant searches
"Lang"
"Block Quotes"
"Lang Comments Block Quotes C#"
"Lang Comments Raw String Literals C#"
"Raw String Literals C# Json"
Document Details
โ Do not edit this section. It is required for learn.microsoft.com โ GitHub issue linking.
- ID: 62bd57d5-0e7d-4355-0689-4b6b90ab4057
- Version Independent ID: 5737c986-9b06-9444-f7bc-893607d390d7
- Platform ID: f6db8a5d-bfbb-6b34-0c0c-0c35c3dc9779
- Content: Raw string literals - """ - C# reference
- Content Source: docs/csharp/language-reference/tokens/raw-string.md
- Service: dotnet-csharp
- Sub-service: lang-reference
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn