Skip to content

[Proposal]: Unions #9662

@MadsTorgersen

Description

@MadsTorgersen

Unions

Note: This consolidates several previous proposals into one. Recent design meeting history for all of them is included below.

Summary

A set of interlinked features that combine to provide C# support for union types, including a declaration syntax and several useful behaviors.

public union Pet(Cat, Dog); // Declaration syntax

Pet pet = dog;              // Implicit conversion

_ = pet switch
{
    Cat cat => ...,         // Implicit matching
    Dog dog => ...,
}                           // Exhaustive switching

Design meetings

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions