11

Introducing C#11: Newlines in string interpolation expressions

 1 year ago
source link: https://anthonygiretti.com/2022/12/04/introducing-c11-newlines-in-string-interpolation-expressions/
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.
neoserver,ios ssh client

Introducing C#11: Newlines in string interpolation expressions

2022-12-04 by anthonygiretti

Introduction

C# 11 brings an improvement on string interpolation. Previously it was impossible, apart from the use of verbatim syntax with @, to write variable text on several lines (only between curly brackets). In this article I will show you that this is possible by example.

String interpolation in action with C# 11

The following code shows the difference between C# 11 and prior versions of C#:

As you can see prior version of C# would have raised the following compilation error:

Error CS8967 Newlines inside a non-verbatim interpolated string are not supported in C# 10.0. Please use language version preview or greater.

Remember! This is only valid for Newlines between curly braces { newslines here only }, the following won’t work:

Helpful right ? 🙂

Like this:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK