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


Interact With Virtual Historic Computers
14/04/2024

Alan Turing's ACE computer is a legendary computer that is particularly special for I Programmer - our account of it was the first ever history article on the site when it launched in 2009. Now this i [ ... ]



Quadrupedal Parkour
31/03/2024

What is it with robots and parkour? First Atlas and now ANYmal want to impress us with their prowess. For the roboticist, however, emulating the skills of free running can enhance the capabilities of  [ ... ]


More News

raspberry pi books

 

Comments




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

Last Updated ( Tuesday, 26 April 2022 )