INDUSTRY NEWS

C# 15 Union Types: The Feature .NET Developers Have Been Waiting For

Curtis Chau
Curtis Chau
Updated: November 16, 2026

Of everything in C# 15, which shipped with .NET 11 on November 10, 2026, union types got the strongest reaction. For years, C# developers have asked for a built-in way to say "this value is one of these types, and nothing else." We first looked at the feature in our .NET 11 Preview 3 review, and now that it has shipped, it's worth a closer look.

In this post our engineering team looks at what union types are, why so many developers are excited about them, and a few things worth knowing before you start using them.

What union types are

A union type is a value that is exactly one of a fixed set of types. You declare it with the new union keyword and list its case types, for example a Pet that can be a Cat, a Dog or a Bird.

A few properties make unions useful:

  • The case types don't need to be related. They don't need a shared base class or interface, so a union can combine types like string and Exception.
  • Conversions are implicit. You can assign any case type directly to the union. Assigning a type that isn't in the list is a compile error.
  • The set is closed. The compiler knows every possible case, which makes exhaustiveness checking possible.

Why it matters: modeling results and outcomes

Many methods have more than one kind of outcome. A lookup can find a user or find nothing. A file operation can succeed, need a password, or hit an unsupported format. Until now, C# had no single built-in way to describe that in a method's signature.

Teams have relied on a mix of patterns:

ApproachThe trade-off
ExceptionsThe failure path isn't visible in the method signature, and exceptions are costly for expected outcomes
Try* methods with out parametersWork well for success or failure, but don't scale to three or more outcomes
Base classes or marker interfacesCan't be closed, so the compiler never knows the set is complete
Custom Result types or third-party union librariesWork well, but each team or library has its own version
Returning object or tuples with nullable fieldsLittle help from the compiler, and lots of defensive checks

Unions give C# a standard answer. A method's return type can list every outcome, and callers can see them all without reading the documentation or the implementation.

Exhaustiveness checking: the compiler has your back

For many developers, the most exciting part isn't the union keyword. It's what the compiler does with it.

When you write a switch expression over a union and handle every case, you don't need a discard or default arm. When you miss a case, the compiler warns you. And when someone adds a new case to the union later, every switch that doesn't handle it gets flagged.

In practice, that turns a whole category of runtime bugs into build warnings. With base classes or interfaces, a new subtype could slip through to a default branch unnoticed. With unions, the compiler shows you every place that needs updating.

Null handling is part of the picture too. If a case type is nullable, the compiler expects a null arm, and a default union value can be matched with a null pattern.

How unions fit with the rest of .NET 11

Unions aren't only a compiler feature. Other parts of .NET 11 support them too:

  • System.Text.Json can serialize and deserialize C# unions, as well as F# discriminated unions.
  • ASP.NET Core supports unions in Minimal APIs and MVC, and describes them with anyOf schemas in generated OpenAPI documents.
  • Closed hierarchies are a companion C# 15 feature. A closed class can only be derived from inside its own assembly, so a switch over its subtypes can also be checked for completeness.
  • Custom unions: existing types can opt in with the [Union] attribute, so libraries that already have their own result types can adopt the compiler support without changing their syntax.

Together, these give C# what Microsoft describes as a more complete exhaustiveness story, whether you prefer unions of unrelated types or a classic class hierarchy.

"The feature I've been waiting for"

The community reaction since the first previews has been very positive. Across blogs, conference talks and social media, the same themes kept coming up:

  • Relief. Many developers had followed the request for years, and "finally" showed up in a lot of headlines.
  • Exhaustiveness checking was the part people were most excited about, more than the syntax itself.
  • More honest method signatures, where a method's return type shows every possible outcome instead of hiding failures behind exceptions.

Our team felt the same way. Like many library authors, we've spent a lot of time thinking about how to communicate several possible outcomes through an API, and having that built into the language is a welcome change.

Things to keep in mind

Unions are a big step, but a few details are worth understanding before you use them widely:

  • They're type unions, not named-case unions. Each case is an existing type, rather than a named case with its own fields like in F#. In practice, records often fill that role.
  • Value types are boxed by default. The generated union stores its value as object?. For performance-sensitive code, custom unions can use a non-boxing access pattern.
  • Adding a case affects callers. Exhaustiveness checking is the point, but it also means a new case produces warnings in every consumer's switch. For public library APIs, that's worth planning for.
  • Tooling and ecosystem support will take time. Serializers, analyzers and third-party libraries will adopt unions at different speeds.

None of these are reasons to wait, but they help when deciding where unions fit best. Starting with internal code and application logic seems like a sensible first step.

Closing thoughts

Union types give C# developers a clearer way to describe outcomes, with the compiler checking that every case is handled. After years of workarounds, it's easy to see why so many developers called it the feature they'd been waiting for. We're looking forward to seeing how the .NET ecosystem adopts it over the next year.

Building with .NET 11? Iron Software's .NET libraries help you work with PDFs, OCR, Excel, barcodes and more in C#. Start your free trial and try them in your next project.