15

Introducing C#11: Raw string literals

 1 year ago
source link: https://anthonygiretti.com/2022/11/29/introducing-c11-raw-string-literals/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introducing C#11: Raw string literals

2022-11-29 by anthonygiretti

Introduction

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:

rawstringliteralcsharp11featured2.png

Bonus! Line breaks are cleared with the Raw String literal syntax unlike the String interpolation and verbatim syntax.

Cleaner isn’t it ? 😉

Like this:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK