---
title: ".NET finally gets union types🎉"
url: https://daily.dev/posts/net-finally-gets-union-types--iyhomcluf
source_url: https://andrewlock.net/exploring-the-dotnet-11-preview-2-dotnet-gets-union-types
type: article
source: ".NET Escapades"
published: 2026-05-19T11:42:38.814Z
updated: 2026-05-19T11:43:01.385Z
tags: [".net", "c#"]
reading_time: 13
upvotes: 1
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# .NET finally gets union types🎉

**[.NET Escapades](https://daily.dev/sources/andrewlock)** · 13 min read · 1 upvotes · 0 comments

## Summary

C# 15 / .NET 11 introduces native union types via the new `union` keyword, a long-requested feature from the functional programming world. The post covers the syntax for declaring unions, how to instantiate and deconstruct them with exhaustive `switch` expressions, and the generated implementation (a `struct` with a single `object? Value` property decorated with `[Union]`). It also explains how to write custom non-boxing union implementations using the `TryGetValue` pattern to avoid heap allocations for struct case types. Setup requirements (preview SDK, `<LangVersion>preview</LangVersion>`) and IDE support status are covered, along with upcoming related features like closed enums and closed hierarchies.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://andrewlock.net/exploring-the-dotnet-11-preview-2-dotnet-gets-union-types>

## Similar posts on daily.dev

- [Explore union types in C\# 15](https://daily.dev/posts/explore-union-types-in-c-15-oygraauhf) · DevBlogs · 64 upvotes · 3 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/net-finally-gets-union-types--iyhomcluf)
