C# 15: Union Types, Closed Hierarchies, and the Unique One Value
Comments
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Summary
Christian Ekrem tried C# 15's new union keyword and closed classes on the .NET 11 release candidate. Switch expressions over a union are exhaustive, but a missing case only raises warning CS8509 unless made an error, and switch statements get no check. Because a union compiles to a struct, default holds a null that no case matches, so the documentation advises a null arm. He also found value types boxed, no built-in Result type, and System.Text.Json failing to deserialize unions. Several findings rest on his own runs.