Microsoft devs rejoice: Union types coming to C# in November
The unsafe keyword will do more heavy lifting, while union types unify disparate forms of data
Microsoft is set to launch the next iteration of C# in November, with the introduction of union types, a feature frequently requested by developers. Union types, which exist in Python, Scala, and TypeScript, allow different custom data types to be categorized into a single entity, providing a more efficient way to handle diverse data.
C# lead designer Mads Torgersen praised this feature, stating it is "how unions should be." Union types enable designs not possible with traditional hierarchies, allowing for better pattern matching, custom functions, and protection against rogue data types. They also reduce boilerplate error code and simplify complex parsing tasks.
Another new feature, closed hierarchies, allows developers to restrict direct inheritance of base classes to only derived types defined within the same assembly, effectively blocking third-party subtypes from being compiled. In addition to these, C# 15 introduces "unsafe" operations with expanded scope, enabling the compiler to flag unsafe code and follow stricter safety protocols similar to Rust and Swift.
Other enhancements include "collection expression arguments" and the ability to declare indexers in an extension block. Despite Microsoft shifting its focus from selling Windows and Office licenses to cloud subscriptions and AI assistant integration, the company continues to update C# regularly.
Written by urgent.news from The Register Science's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.
- Microsoft devs rejoice: Union types coming to C# in November theregister.com