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


Grace Hopper Award Recognizes Contribution To Secure Computation
20/05/2022

Raluca Ada Popa, an associate professor of Computer Science at UC Berkeley, is the recipient of the 2021 ACM Grace Murray Hopper Award for the design of secure distributed systems. These systems  [ ... ]



Android Studio Chipmunk - Cute But Increasingly Unfit For Purpose
11/05/2022

The latest release of Android Studio has many fixes and many additions, but is still on track to be sidelined by something better. Android development is a mess and the tools just aren't helping.


More News

pythondata

 



 

Comments




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

Last Updated ( Tuesday, 26 April 2022 )