Other

C# 15 and .NET 11: union types, closed hierarchies and more

DEV Community: #csharp Khaja Hussain
Other

Released on November 10, 2026, .NET 11 and C# 15 bring long-requested features such as union types and closed hierarchies. The article walks through what each feature does, when it pays off, and which runtime to target in production.

Key points

  • A union declared with `public union Pet(Cat, Dog, Bird);` gives exhaustive checks in switch expressions.
  • `closed record class` can only be derived in the same assembly and is implicitly abstract.
  • Collection expressions now accept constructor arguments via `[with(StringComparer.OrdinalIgnoreCase), "csharp"]`.
  • Extension blocks can declare an indexer such as `this[int index]`; the receiver must be a named parameter.
  • Labeled `break outer;` and `continue outer;` replace flag variables, and the IDE0410 analyzer flags old patterns.
  • ASP.NET Core 11 defaults OpenAPI docs to 3.2, a breaking change for client generators and Swagger tooling.

Why it matters

Union types move into the language a problem that teams have solved with libraries like OneOf or object-plus-casts, so anyone writing return types, API contracts and error models is affected. The real gain is not the syntax but the compiler telling you which switch statements you left behind when a new case appears.

The upgrade side is more urgent than the features. With .NET 8 and 9 out of support as of November 10, 2026, applications without security patches should move to .NET 10 LTS first, whatever else you adopt. Teams that prefer LTS in production should note the 24-month STS window of .NET 11 and test client generators against the OpenAPI 3.2 default.

Real-world use

  • Modeling success, not found and validation failures as a union return type instead of exceptions or nulls.
  • Mapping a union-typed service result to `Results.Ok`, `Results.NotFound` and `Results.Conflict` in an endpoint.
  • Using `[with(capacity: ...), .. values]` collection expressions to pre-size lists before copying items in.
  • Escaping nested loops with a labeled break when searching a collection inside a search loop.

This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message