Last updated: October 22, 2026 · Tested with .NET 11 RC2 (SDK 11.0.100-rc.2.26504.105, C# 15) and the .NET 10.0.12 runtime Short answer: C# 15 adds union types . You declare one with the union keyword and a list of case types. Any value of a case type converts to the union implicitly, and a switch expression over the union is checked for exhaustiveness: no _ => arm needed, and you get a warning if you forget a case. public record class Cat(string Name); public record class Dog(string Name); public record class Bird(string Name); public union Pet(Cat, Dog, Bird); // 1. Basics: implicit conversion and an exhaustive switch Pet pet = new Dog("Rex"); Console.WriteLine($"1. {Describe(pet)}"); static string Describe(Pet pet) => pet switch { Dog d => $"dog {d.Name}", Cat c => $"cat {c.Name}", Bird b => $"bird {b.Name}", }; That's the feature most C# developers have asked for under the name "disc...
CSharp-Coder
CSharp-Coder.com is a free online resource dedicated to helping both beginner and advanced developers learn and improve their programming skills. The website offers a variety of tutorials, articles, and resources designed to make learning programming easy and fun.