C# 11 Preview

All C# developers are looking forward to the release of a new version of the language, which is already declared as version 11. It should also be noted that according to official information, this version will be the last version of C#. Its release is tentatively planned for November 2022.

Also important is that version 11 will be equipped with the sprinkled ” go-live ” support announced by Microsoft. In our case, this is very good news, since Microsoft itself will provide active support for applications written or adapted for C # 11.

Microsoft has repeatedly fueled interest in the new version of the language, and only recently has reliable information appeared about innovations and features with faced by developers. One of these features was the possibility of a multiline string during interpolation, let’s talk about this in more detail.

New String Interpolation Features

Previously, the language supported two types of interpolation: the first was verbatim interpolation ($@””) and non-verbatim interpolation ($””). The main differences between these types were that, with verbatim interpolation, strings can contain variables, there is no need to connect a string with a piece of code or a variable when, for example, we want to display a message. We don’t need to escape quotes. Non-verbatim interpolated strings use escape characters , for example: /n. It looks very complicated, let’s look at an example of what has changed in the new version of the language using the construction example:

var p = $"Result ist : { This.Is .Really.Something () . That.I.Should (
Be Able)[ To.Wrap ()] }.";

New list templates

Innovations have not bypassed list templates . It is also a very nice feature to compare arrays and lists, match different elements, include a cut pattern starting from 0 or more elements.

Checking the null value of the parameter.

Each developer is faced with the need to check the variables and values that come into the processed code. For this, a structure of the form is often used:

if (variable is null)
{
throw new ArgumentNullException ( nameof (variable));
}

The new version of the language introduces the possibility of checking thanks to just two characters ! !. Example:

public static void Check (string variable!!)

{
}

Everything became beautiful and concise. Adding these characters will generate a verification code. Provided that the method has several parameters, then the check will be performed sequentially.

Name of types and names scoped , file , required

The new version has one feature in terms of the name ” scoped “. Now we can’t call the written type ” scoped “. The word is reserved, however there are workarounds such as escaping. This allows you to name the class, before the name itself we will set the @ sign. Example:

class @scoped {}

The same goes for the name file , required.

Handling string literals

The new version announced additional processing of string literals, which was not there before. This allows you to use special characters without escaping them. The new format also allows for built -in encodings, newlines, and spaces.

To process string literals, we just need to use triple quotes at the beginning and end of our character text.

Updated math support

Generic update Math has introduced many features. Now we can use various operators from common contexts .

Also updated Generic support Math with various functions such as:

  • Members that are static and virtual in interfaces
  • Relaxed Right Shift Requirements
  • Unsigned right shift operator


Conclusions

In this article, we looked at the new features and features of the C# language. By the time of release, more features are likely to appear, but we can test many of them today.