Giorgi Kobaidze uses an age parser to explain typed outcomes in “C# 15 Unpacked: Practical Use Cases for Unions with Real Examples.” The example returns either a parsed integer or a record carrying an error message. Original DEV article
Where the reason for failure lives
Kobaidze starts with a method built around the familiar try-parse pattern. It returns false if the input fails integer parsing or falls outside the example's accepted range. At the call site, those failures look the same. The article also shows a throwing version, where callers can get more detail by handling exceptions.
The union version gives the method a return type called ParseResult<int>. On successful parsing and validation, it returns the age. On failure, it returns a ParseError with a message. Text such as abc exercises the integer parsing branch, while 200 exercises the range check after parsing has succeeded. Those cases share an error type, so the caller can display both messages through the same branch.
What the switch needs to handle
The console example matches an integer to produce a success message and matches a ParseError to display the explanation. The union declaration defines the case types visible to the compiler. Microsoft documents that C# 15 checks switch expressions for coverage of those types, and that projects targeting net11.0 select C# 15 by default with the .NET 11 SDK. Microsoft C# union tutorial
There are two distinct design choices in the example. The parser distinguishes the reasons for failure in the message, while the switch distinguishes success from failure in the type. That is enough for a console loop that just prints the result. A caller that needs to react differently to malformed text and an out-of-range age would need a structured way to distinguish them, such as a reason field on the error record. For a parser you maintain, which failures need to drive caller behavior, and which only need to be explained to the user?