Microsoft has announced a long-awaited feature for C# — union types, which will appear in the fifteenth version of the language and are already available in the .NET 11 preview.
The new mechanism allows you to explicitly specify a limited set of possible types for a variable and ensures that your code processes each of them at compile time.
This makes it easier to work with heterogeneous data and eliminates old trade-offs such as using object or base classes.