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


Go At Highest Rank Ever in TIOBE Index
20/11/2024

Go is currently in 7th place in the TIOBE Index for November 2024. Not only is this is the highest position it has ever had, it's percentage rating is almost equal to its all-time-high. Will Go contin [ ... ]



AI Propels Python To Top Language on GitHub
30/10/2024

This year's Octoverse Report reveals how AI is expanding on GitHub and that Python has now overtaken JavaScript as the most popular language on GitHub. The use of Jupyter Notebooks has also surged.


More News

espbook

 

Comments




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

Last Updated ( Tuesday, 26 April 2022 )