Union types, closed hierarchies and the first preview of the updated memory safety model.
This release added 6 features, each with a before-and-after example.
Features in C# 15.0
- Closed hierarchies - Mark a class as closed so only types in its own assembly can derive from it, enabling exhaustive switches.
- Collection expression arguments - Pass capacity, comparers and other constructor arguments from inside a collection expression.
- Extension indexers - Add indexers to existing types from an extension block.
- Labeled break and continue - Break out of or continue an outer loop directly from inside nested loops.
- Memory safety - Pointer relaxations, requires-unsafe members and unsafe expressions tie unsafe to the operations that access memory.
- Union types - Declare a type that holds exactly one of several case types, with exhaustive switch checking.