|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.
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.
Summer SALE Kindle 9.99 Paperback $10 off!!
or email your comment to: email@example.com
|Last Updated ( Tuesday, 26 April 2022 )|