Skip to content

C# Feature - Union types

Union types represent a value that can be one of several case types, with compiler support for conversions and exhaustive switching.

This feature is documented as part of C# 15 preview. The official Microsoft Learn page is dated March 20, 2026 and says C# 15 preview is available with the .NET 11 preview SDK and Visual Studio 2026 Insiders. The same page notes that union types first appeared in .NET 11 Preview 2.

C# has long supported inheritance hierarchies, records, and pattern matching, but it did not have a first-class language construct for “exactly one of these cases.” Union types make that intent explicit.

public record class Cat(string Name);
public record class Dog(string Name);
public record class Bird(string Name);
public union Pet(Cat, Dog, Bird);

Usage:

Pet pet = new Dog("Rex");
string name = pet switch
{
Dog d => d.Name,
Cat c => c.Name,
Bird b => b.Name,
};
  • Use it when a model should be exactly one of a small number of known alternatives.
  • Use it when exhaustive switching is part of correctness.
  • This feature is still preview-only as of March 20, 2026.
  • The Microsoft docs note that some runtime support and proposal details were still incomplete in early .NET 11 previews.