C# 11, the planned next version of Microsoft’s popular object-oriented, type-safe programming language, is nearly complete and continues to add capabilities, including object-initialisation improvements and generic math support.
With object initialisation, developers can more easily support constructors and object initialisers in their type, independent of rules to enforce for immutable and mutable members. Features include required members and
With generic math, meanwhile, developers can write algorithms once for multiple numeric types. This makes it easier to use C# and .NET for machine learning, statistics, and other math-intensive applications. Capabilities are included such as relaxed right-shift requirements, an unsigned right-shift operator, static abstract and static virtual members in interfaces, and numeric
Microsoft is touting these as new features added to the language in the Visual Studio 2022 17.3 IDE, which became available on August 9.
Previous improvements in C# 11 covered areas such as raw string literals and list patterns. For developer productivity in C# 11, the
nameof operator now can be used with method parameters, as of Visual Studio 2022 17.3. This enables developers to use this operator in attribute declarations on methods.
Also new in C# 11, the compiler ensures that fields of a
struct type are initialised to their default values as part of executing a constructor.
This means any field or auto property not initialised by a constructor is initialised automatically by the compiler. Structs where the constructor does not definitely assign all fields now compile, and any fields not explicitly initialised are set to their default value.
For pattern matching, the same pattern matching logic that has been used to test if a
string had a specific constant value now can be used with variables that are
To try the latest C# 11 features, developers can download the latest preview of Visual Studio 2022 and install the .NET 7 preview. Developers also can separately install the latest preview of .NET 7. A final release of .NET 7 is expected in November.