
c# gets union types in .net 11 preview 2
C# in .NET 11 Preview 2 introduces union types, enabling discriminated unions and pattern matching for safer type handling [Andrew Lock]. This feature lands after years of community requests.
C# in .NET 11 Preview 2 adds union types, a language-level feature that enables discriminated unions and exhaustive pattern matching [Andrew Lock]. The feature introduces a new union keyword to define types that can hold one of several distinct shapes, such as union Result<T> { Success(T value); Error(string message); }, creating a type-checked sum type. The compiler enforces exhaustive matching, triggering a warning for omitted cases, upgradable to an error via #pragma warning [Andrew Lock].
The implementation builds on nullable reference types and recursive patterns from C# 8–10. It does not yet support unnamed tuple-style unions, only named cases in a union declaration, as seen in .NET 11.0.0-preview.2.26212.1, released May 22, 2026 [Andrew Lock].
Union types will displace null, Exception, and out parameters as the preferred way to model fallible operations. Teams adopting them will see fewer NullReferenceException crashes in production, as the type system forces error path handling. F# has had discriminated unions since 2005, and their arrival in C# validates a decade of F# advocacy inside Microsoft. C#’s version offers stronger exhaustiveness checks out of the box compared to TypeScript’s tagged unions, which have been available since 2017 [Andrew Lock].
Subscribe to the broadcast.
Daily digest of the day's most important tech news. No fluff. Engineering signal only.
// delivered via substack · double-opt-in confirmation


