Paul Krill
Editor at Large

Microsoft’s C# 11 language upgrade nears the finish line

news
Aug 23, 20222 mins

Object initialization and generic math get attention in the latest improvements to the well-known programming language.

man running across finish line
Credit: Thinkstock

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-initialization improvements and generic math support.

With object initialization, developers can more easily support constructors and object initializers in their type, independent of rules to enforce for immutable and mutable members. Features include required members and ref fields. 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 IntPtr].

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 initialized to their default values as part of executing a constructor. This means any field or auto property not initialized by a constructor is initialized automatically by the compiler. Structs where the constructor does not definitely assign all fields now compile, and any fields not explicitly initialized 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 Span<char> or ReadOnlySpan<char>.

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author