If you’re coming to C# from a language like Typescript, you might be wondering, “how do I write a discriminated union?” Unfortunately, C# does not currently support unions as such, but other language features can get you pretty close. Plus, native support might be just over the horizon.

The State of Union Types in C

A formal proposal to add unions to C# was added last year to the C# language repository. The proposal explores adding a concise syntax for declaring a type that can be one of several named alternatives, each potentially containing its own data payload. A first-class union type would bring C# closer to features that have been widely adopted in functional …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help