Explore union types in C# 15

C# adds pick‑one types; fans say “finally”, critics want Rust/F# magic

TLDR: C# 15 (in .NET 11 Preview 2) adds union types so values can be one of a few allowed types, with the compiler checking you handle every case. Devs are split: some celebrate safer code, others complain it lacks Rust‑style power and F# flexibility, fueling a broader “is C# bloating?” debate.

C# just dropped union types in its C# 15 preview, and the crowd is anything but united. In plain English: unions let a value be exactly one of a few approved types, and the compiler makes you handle every case—no mystery surprises at runtime. Microsoft’s demo goes full “pet store,” letting a variable be a Cat, Dog, or Bird, and the language checks you cover them all. Neat! But the comments? Spicy.

One camp is thrilled this cleans up messy “anything goes” code. Another says it’s too safe, too small. A top gripe: this isn’t the ultra-flexible, on‑the‑fly version fans know from F# or the powerful “enums with data” folks love in Rust. As one commenter put it, C# got a sealed box—but not the magic trick inside. That kicked off a bigger identity crisis: is C# evolving or kitchen‑sinking? One nostalgic voice mourned that pulling F# ideas into C# turns it into “a big bag of stuff,” while another asked whether C# is “a great language trapped in a terrible ecosystem.”

Meanwhile, the meme-makers got to work. The top quip: “#define struct union.” Translation: developers cope with change using jokes. Love it or loathe it, unions are here, and the debate is louder than a kennel at feeding time. Read the preview and pick a side.

Key Points

  • C# 15 introduces a union keyword in .NET 11 Preview 2 to define closed union types.
  • Union types compose unrelated existing types and enforce exhaustive switch expressions without default arms.
  • The compiler provides implicit conversions from each case type to the union and errors on non-case assignments.
  • Patterns match the union’s Value property automatically; var and _ apply to the union value itself.
  • Nullability is respected: nullable case types require a null arm; default union struct has Value = null.

Hottest takes

"aren't supporting Rust-style discriminated unions" — 98347598
"a big bag of stuff, with no direction" — FrustratedMonky
"a great language trapped in a terrible ecosystem?" — gib444
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.