Introducing C#11: Raw string literals
C# 11 brings new syntax for writing plain text. Instead of relying on string interpolation with the character $ and the verbatim with @ character for writting on several lines, C# 11 allows using three double quotes. There is no need to double the quotes in the text to escape a double quote anymore. In this post, I will show you a simple example of it!
Raw string literals in action
The benefit of the three double quote syntax is that whitespaces before and after line breaks are eliminated. The following piece of code shows respectively: an unvarying text with words surrounded by double quotes, a variable text, and the combination of string interpolation and the verbatim symbol (prior C# 11 syntax):
The code above outputs the following:
Bonus! Line breaks are cleared with the Raw String literal syntax unlike the String interpolation and verbatim syntax.
Cleaner isn’t it ? 😉