TL;DR
Microsoft announced the addition of union types in C# 15 as part of .NET 11 preview 4. This feature allows developers to define variables that can hold multiple, distinct types, improving type safety and code clarity. The feature is currently in preview and subject to change before the final release.
Microsoft has officially added support for union types in C# 15 as part of the .NET 11 preview, enabling developers to define variables that can hold multiple, unrelated types. This feature, long requested by the developer community, aims to improve type safety and reduce boilerplate code in complex applications.
The union types feature was introduced in .NET 11 preview 4, and it allows defining a variable that can contain one of several specified types. Using the new union keyword, developers can declare a variable that can hold, for example, either a Windows, Linux, or MacOS record type, without resorting to base classes or object casting.
For example, a supported OS union can be declared as public union SupportedOS(Windows, Linux, MacOS);. Instances can be created directly via constructor or implicit conversion, and the type can be safely pattern-matched using switch expressions. The generated union type implements an IUnion interface, providing access to the stored value via a Value property.
To use this feature, developers must install the .NET 11 preview SDK, enable preview language features in the project file, and target the appropriate frameworks. The support is still in preview and may undergo changes before the final release.
Why It Matters
This development introduces a powerful new way for C# developers to handle multiple data types safely and more expressively, aligning C# closer to functional programming paradigms. It reduces the need for workarounds like base classes, type tags, or unsafe casting, leading to cleaner, more maintainable code. The feature could influence how APIs are designed, especially those involving data that can take multiple forms.

The C Programming Language
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
Union types have been a staple in functional languages like F#, Rust, and TypeScript for years, providing a safe way to handle data that can be one of several types. You can learn more about their role in modern programming. Their absence in C# has often led developers to use less safe patterns. The addition in C# 15 represents a significant language evolution, responding to longstanding community requests. The support was first introduced in preview in early 2026, with ongoing refinements expected before the final release of .NET 11.
“Union types in C# 15 bring a new level of expressiveness and safety for handling multiple data types, aligning C# with modern functional programming practices.”
— Microsoft C# team
“This feature will simplify many patterns I currently implement with base classes or object casting, making code cleaner and safer.”
— Developer community member
.NET 11 preview SDK download
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
It is not yet clear how widely adopted union types will become before the final release, or how they will perform in large-scale applications. The feature is still in preview, and some aspects of the implementation may change. Additionally, full tooling support and best practices are still evolving.

C# in Depth: Fourth Edition
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Microsoft will continue refining union types in subsequent preview releases, with the final version expected before the official release of .NET 11. Developers are encouraged to experiment with the feature in preview environments and provide feedback. For more insights on AI trends, visit this article. Future updates may include expanded documentation, tooling improvements, and additional language features to complement union types.
![MixPad Free Multitrack Recording Studio and Music Mixing Software [Download]](https://m.media-amazon.com/images/I/71ltIxIuz1L._SL500_.jpg)
MixPad Free Multitrack Recording Studio and Music Mixing Software [Download]
Create a mix using audio, music and voice tracks and recordings.
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
What are union types in C#?
Union types allow a variable to hold one of several specified types, providing a safer and more expressive alternative to using object or base class references.
How do I enable union types in my project?
You need to install the .NET 11 preview SDK, enable preview language support in your .csproj file by adding , and target frameworks like net11.0.
Are union types stable and ready for production?
No, they are currently in preview (version 4 of .NET 11) and may undergo changes. Developers should use them cautiously in experimental or testing environments.
Can I implement my own union types?
Yes, the feature supports creating custom union types, and the API provides mechanisms to work with them safely, including pattern matching and value extraction.
Source: Hacker News