C#11 Will Support Raw String Literals
Written by Kay Ewbank   
Tuesday, 26 April 2022

Details of what Microsoft is adding to C# 11 have been released, with changes concentrating on better performance along with new language features including raw string literals and checked user-defined operators.

The improvements are already available for developers using Visual Studio 17.2 Preview 3 or .NET 7 Preview 3.

c

The C# team says that developers who work with strings literal that contain quotes or embedded language strings like JSON, XML, HTML, or SQL may find the support for raw literal strings their favorite feature of C# 11. Previously if you copied a literal string with quotes into a C# literal, the string ended at the first double quote with compiler errors until you escaped each one. Raw string literals have no escaping.

Support has also been added for UTF-8 string literals. Until now, C# programmers had to either translate UTF-8 into hexadecimal or encode string literals at runtime. C# 11 allows converting string literals containing only UTF-8 characters to their byte representation.

Checked user-defined operators are another improvement in the new version. This will enable C# to support generic math, and while the C# team says they anticipate that only a small number of developers will use this feature directly, the impact of their implementations will make the entire ecosystem more reliable and predictable. User-defined operators respect the context of the calling code in the way arithmetic overflow and underflow are defined. Until now, C# user-defined operators were unaware of the context in which they were used. C# 11 adds the ability to declare certain operators as checked, identified with the checked modifier.

Pattern matching with spans is another addition, meaning you can pattern match a Span<char> or a ReadonlySpan<char> with a string literal. The addition opens the use of spans as patterns in switch statements and switch expressions for matching string literals.

C# will be part of the .NET SDK.

c

More Information

Visual Studio 17.2 Preview 3

.NET 7 Preview 3 

Related Articles

Welcome Improvements in C# 10

C# 8, What's Coming

C# 8.X Plans Revealed

C# Guru - An Interview With Eric Lippert

Project Rider A Cross Platform C# IDE

C# Joins PVS-Studio Line Up

C# 7 Features

C# 7 - What Would You Put In?

C# Gets A New Operator - Safe Navigation

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Datalore 2023 Updates Reporting
04/11/2022

JetBrains has updated Datalore, its collaborative data science platform for teams, which is available both on-premises and in the private cloud. Datalore Enterprise 2023 has improvements to the r [ ... ]



Hour Of Code Goes Into Space
30/11/2022

Code.org has gone all out to celebrate its 10th year. No longer just a global event, Hour of Code, which starts on December 5, has gone extra terrestrial with an hour-long feature about Computer  [ ... ]


More News

picobook

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Tuesday, 26 April 2022 )