Particulars of what Microsoft is including to C# 11 have been launched, with modifications concentrating on higher efficiency together with new language options together with uncooked string literals and checked user-defined operators.
The enhancements are already out there for builders utilizing Visible Studio 17.2 Preview 3 or .NET 7 Preview 3.
The C# staff says that builders who work with strings literal that comprise quotes or embedded language strings like JSON, XML, HTML, or SQL could discover the help for uncooked literal strings their favourite characteristic of C# 11. Beforehand in the event you copied a literal string with quotes right into a C# literal, the string ended on the first double quote with compiler errors till you escaped each. Uncooked string literals haven’t any escaping.
Help has additionally been added for UTF-8 string literals. Till now, C# programmers needed to both translate UTF-8 into hexadecimal or encode string literals at runtime. C# 11 permits changing string literals containing solely UTF-8 characters to their byte illustration.
Checked user-defined operators are one other enchancment within the new model. This may allow C# to help generic math, and whereas the C# staff says they anticipate that solely a small variety of builders will use this characteristic straight, the affect of their implementations will make your complete ecosystem extra dependable and predictable. Person-defined operators respect the context of the calling code in the way in which arithmetic overflow and underflow are outlined. Till now, C# user-defined operators have been unaware of the context by which they have been used. C# 11 provides the flexibility to declare sure operators as checked, recognized with the checked modifier.
Sample matching with spans is one other addition, which means you possibly can sample match a Span<char> or a ReadonlySpan<char> with a string literal. The addition opens the usage of spans as patterns in swap statements and swap expressions for matching string literals.
C# shall be a part of the .NET SDK.
Extra Data
Associated Articles
C# Guru – An Interview With Eric Lippert
Project Rider A Cross Platform C# IDE
C# Gets A New Operator – Safe Navigation
To learn about new articles on I Programmer, join our weekly newsletter, subscribe to the RSS feed and comply with us on Twitter, Facebook or Linkedin.
Feedback
or e-mail your remark to: [email protected]