Blog Logo
TAGS

[LDM] - Union Types · dotnet/csharplang · Discussion #7010 · GitHub

This is a summary of discussions held on discriminated unions in C# by members of the C# language design team. Union types are types where instances represent a single case from a closed set of possible cases. The goals for C# are to make it possible to consume existing union types in pattern matching, define new union types easily, and define unions of existing types. Currently, there are many existing types that are understood by the language but are not technically closed or are closed but are not understood by the language. Examples of types that C# understands but are not closed include enums. Variables of enum type can contain any integer value available to the underlying type and thus are not closed. This discussion was started by mattwar on Feb 28, 2023, and has 23 answers and 69 replies as of this writing.