<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/union-types-in-c--jtlxv0quk" -->

---
title: Union types in C# | daily.dev
description: C# lacks native union types, but several workarounds exist. Using abstract records with a private constructor simulates discriminated unions and enables...
canonical: https://daily.dev/posts/union-types-in-c--jtlxv0quk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Union types in C# | daily.dev
og:description: C# lacks native union types, but several workarounds exist. Using abstract records with a private constructor simulates discriminated unions and enables...
og:url: https://daily.dev/posts/union-types-in-c--jtlxv0quk
og:image: https://api.daily.dev/og/posts/JTLxv0QuK.png
og:image:alt: Union types in C#
og:image:width: 1200
og:image:height: 630
og:locale: 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.

# Union types in C#

**[Event-Driven by Oskar Dudycz](https://daily.dev/sources/event-driven-io)** · 12 min read · 0 upvotes · 0 comments

## Summary

C# lacks native union types, but several workarounds exist. Using abstract records with a private constructor simulates discriminated unions and enables pattern matching for domain modeling (e.g., shopping cart states). For simpler cases, tuples with nullable fields can work, though they're verbose. A custom Maybe<T> type and Either<TLeft, TRight> class provide cleaner semantics, including Map and Switch methods for exhaustive handling. For three or more types, a OneOf<T1,T2,T3> class or the existing OneOf library can be used. The author recommends applying these patterns selectively in domain/business logic code, while cautioning against over-engineering, and advocates for native C# union type support.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://event-driven.io/en/union_types_in_csharp>

## Similar posts on daily.dev

- [Working union types into C\#](https://daily.dev/posts/working-union-types-into-c--n1rhxnbqf) · Atomic Spin · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#c#](https://daily.dev/tags/c#), [#functional-programming](https://daily.dev/tags/functional-programming)

[View this post on daily.dev](https://daily.dev/posts/union-types-in-c--jtlxv0quk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Union types in C#","url":"https://daily.dev/posts/union-types-in-c--jtlxv0quk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/union-types-in-c--jtlxv0quk"},"datePublished":"2026-06-17T11:26:23.933Z","dateModified":"2026-06-17T11:34:25.879Z","description":"C# lacks native union types, but several workarounds exist. Using abstract records with a private constructor simulates discriminated unions and enables...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0edb66ea36d1bdc3529ccb123def389e?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0edb66ea36d1bdc3529ccb123def389e?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Event-Driven by Oskar Dudycz","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Event-Driven by Oskar Dudycz","logo":"https://media.daily.dev/image/upload/s--unDKCFQ0--/f_auto,q_auto/v1781695550/logos/event-driven-io?_a=BAMAMiWQ0","url":"https://daily.dev/sources/event-driven-io"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/union-types-in-c--jtlxv0quk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,c#,functional-programming","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Event-Driven by Oskar Dudycz","item":"https://daily.dev/sources/event-driven-io"},{"@type":"ListItem","position":3,"name":"Union types in C#"}]}
```

