Update raw-string-literal.md

This commit is contained in:
CyrusNajmabadi 2021-08-20 12:09:52 -07:00 committed by GitHub
parent 341d5184ba
commit 8255f7d434
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,6 +50,12 @@ var xml = """
""";
```
A single line form is also supported. It starts with a minimum of three `"""` characters (but no maximum), the content of the string (which cannot contain any `new_line` characters), and then ends with the same number of quotes that the literal started with. For example:
```
var xml = """<summary><element attr="content"/></summary>""";
```
## Motivation
C# lacks a general way to create simple string literals that can contain effectively any arbitrary text. All C# string literal forms today need some form of escaping in case the contents use some special character (always if a delimiter is used). This prevents easily having literals containing other languages in them (for example, an XML, HTML or JSON literal).