dotnet / dotnet/docs

[C# 15-Fundamentals and reference]: New Feature - unions

Open
#52,320 0 comments 0 reactions 1 assignee Claimed by @BillWagner View on GitHub
:checkered_flag: Release: .NET 11 :pushpin: seQUESTered dotnet-csharp/svc whats-new/subsvc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

### .NET 11 Preview

.NET 11 Preview 3

### Link to speclet

- [Speclet](https://github.com/dotnet/csharplang/blob/main/proposals/unions.md)

### Link to Pull request

- [PR](https://github.com/dotnet/roslyn/pull/82640)

### New behavior

The `union` keyword creates a new type: a union where the member `Value` is an instance of exactly one of the declared union members.

### Language reference tasks

- The `union` keyword defines a new type that is lowered as a `record struct`. A `union` type holds an instance of one of its members.
- Update pattern matching to discuss exhaustiveness and subsumptiom related to unions.
- Update casts to include union casts (implicit and explicit)

### Everyday C# tasks

- Add information about unions for "one of" and "Result" style scenarios.

---
[Associated WorkItem - 562440](https://dev.azure.com/msft-skilling/Content/_workitems/edit/562440)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.