dotnet / dotnet/docs

Please provide example for combining raw string literals with interpolated string

Open
#42,727 2 comments 0 reactions 0 assignees View on GitHub
dotnet-csharp/svc lang-reference/subsvc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

### Type of issue

Missing information

### Description

I keep forgetting how to combine raw string literal with interpolated strings which I use, but obviously not use enough apperantly, when testing and building json objects.
And my issue is the text here is just not clear enough for me to understand I both have to use multiple $ characters _and_ multiple { and } so it would be very beneficial with an actual example in the documentation, something like 🙂

```c#
string jsonPayload = $$"""
{
"firstName": {{firstname}},
"lastName": "{{lastname}}"
}
""";
```

[Enter feedback here]
Raw string literals can also be combined with [interpolated strings](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated#interpolated-raw-string-literals) to embed the { and } characters in the output string. You use multiple $ characters in an interpolated raw string literal to embed { and } characters in the output string without escaping them.

### Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string

### Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/tokens/raw-string.md

### Document Version Independent Id

5737c986-9b06-9444-f7bc-893607d390d7

### Article author

@BillWagner

### Metadata

* ID: 62bd57d5-0e7d-4355-0689-4b6b90ab4057
* Service: **dotnet-csharp**
* Sub-service: **lang-reference**

[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+5737c986-9b06-9444-f7bc-893607d390d7)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.