Press "Enter" to skip to content

Discriminated Unions in F# and C#

The NDepend blog talks discriminated unions:

In recent years, there has been a notable surge in inquiries from the C# community regarding language-level support for C# Discriminated Unions. What individuals truly desire is the ability to express complex data structures more elegantly and effectively.

This blog post offers a thorough introduction to simulating Discriminated Unions (DUs) in C# programs, highlighting their usefulness.

Discriminated Unions, also known as “or” types (because you select one from the set of options), are really powerful concepts in functional programming. And this article gives you a way to simulate the approach in C#, at least until C# catches up to F# in this aspect.