.NET 11 and C# 15 have shipped, bringing discriminated union types, closed hierarchies, runtime-native async and multi-file file-based apps. It is a Standard-Term Support release with a decade-old language request finally landing in the compiler.
Key points
- Union types declare a fixed set of case types with `public union PaymentMethod(CreditCard, PayPal, BankTransfer)`.
- Switch expressions become exhaustive without a default branch, and a missing case raises a compiler warning.
- Runtime Async removes compiler-generated state machines when `runtime-async=on` is set in the project.
- Live stack traces drop from 13 frames to 5, and synchronous completion falls from 21.2 ns to 6.2 ns.
- The `closed` modifier restricts derivation to the declaring assembly, enabling exhaustiveness on hierarchies.
- File-based apps can span multiple files and reference DLLs through the `#:include` directive.
Real-world use
- Handlers that return one of several unrelated outcomes, such as a payment method or a create-order result
- Minimal API endpoints that map each outcome to an HTTP 201, 409 or 400 response instead of throwing
- Closed hierarchies like shipment statuses that only the owning assembly may extend
This summary was generated by the agent from the original post on Anton DevTips. The full text and all rights belong to its author and publisher. Go to original