16 November
C# 11 – String interpolated new line
Programming
min. read

Let’s list all the features that C# 11 brings to the table. Let’s discuss them all one by one, with their use cases, and see how they can come in handy. At the bottom of each article, you can find a link to all 14 new C# features!
String interpolated new line
In the previous releases of C#, we had problems when we tried to create a line break in the middle of a verbatim block.
var variable = "World";
var verbatim = $"Hello {variable.ToLower()}"; // Ok
var error = $"Hello {variable. // <- error before C# 11
ToLower()}";
In new C# 11, you can now make line breaks in the middle of the variables. This will be useful for use cases when the line is too long and you are looking at the place to break it!
This is still one line when you print it!
Still in C# 10, how to do it then?
Before you had only the following options:
var break1 = "Hello " +
$"{variable.ToLower()}";
// This one might be inconvinient as it might print in 2 separate lines.
var break2 = [email protected]"Hello
{variable.ToLower()}";
I like this change, it’s convenient!
Further reading at dotnet GitHub page.
Author
About prog
Founded in 2016 in Warsaw, Poland. Prographers mission is to help the world put the sofware to work in new ways, through the delivery of custom tailored 3D and web applications to match the needs of the customers.
SIMILAR POSTS
C# 11 – UTF-8 string literals
Programming
min. read
C# 11 – Everything you need to know
Programming
min. read
C# 11 – Generic Math Support
Programming
min. read