Union types in C# | DEM304

Mads Torgersen and Dustin Campbell explore the upcoming union types feature in C#, focusing on how unions represent closed sets of possible shapes (often seen in wire protocols) and how that enables cleaner, more confident consuming code.

Overview

Union types are presented as a way to model a fixed (closed) set of alternatives in a single type, improving readability and correctness when handling multiple possible outcomes.

Key ideas

Unions as closed sets of data shapes

Cleaner consuming code

Exhaustive handling with switch

Implementation approach (struct-based)

Performance considerations

Patterns and conventions

Preview and tooling

Resources