Union types in C# 15: modeling closed sets of unrelated types
Mads Torgersen introduces union types coming in C# 15, showing how they let you model a closed set of unrelated types, create union values, and switch over them with full strong typing. He also points to a preview compiler you can try in Visual Studio and VS Code.
Overview
The video highlights union types as an upcoming C# feature.
What union types enable
- Model a closed set of unrelated types under a single union type.
- Create union values from the allowed member types.
- Use
switch/pattern matching to switch over union values in a fully strongly typed way.
Availability
- The feature is described as landing in C# 15 (this November).
- A preview compiler is available to try now in:
- Visual Studio
- VS Code