Microsoft has announced new features available in the preview of C# 15, the version that will arrive with .NET 11. The update includes union types, closed hierarchies, and a preview of the updated model for handling unsafe code, along with smaller changes intended to reduce repetitive procedural code in everyday use.
Arguments Inside Collection Expressions
C# collection expressions can convert values into multiple types of collections, but they previously did not allow arguments to be passed to the primary constructor or factory method. C# 15 adds a new element in the form of with(...), placed at the beginning of the expression, to pass these arguments.
This makes it possible, for example, to create a list while specifying its capacity directly inside the expression, or to create a HashSet while passing StringComparer.OrdinalIgnoreCase, instead of separating creation from adding the elements. Microsoft notes that this capability paves the way for the anticipated dictionary expression syntax, which will likely need to specify the comparer used for keys.
Accessing Elements Through Extension Indexers
After C# 14 added extension members for properties and operators alongside methods, C# 15 expands this model to include extension indexers. This makes it possible to access an element from a receiver object as though the indexer were originally defined within its type.
In the example presented by Microsoft, accessing an element in IEnumerable<int> required a helper method such as ElementAtIndex. The new syntax allows numbers[2] to be used through an extension indexer associated with the receiver. The blog explains that indexers cannot be static, so the extension container must include a named receiver.
Labels for break and continue Loops
C# 15 allows iteration loops to be labeled and then directs break or continue to them directly. This is useful in nested loops, where exiting the outer loop previously typically required a Boolean variable, using goto, or moving the logic into a separate function.
In practice, labeling makes the exit target clear within the code and eliminates the need for a variable to track whether the desired element was found. The example shows a loop labeled scan that can be exited directly using break scan.
What Changes for Developers?
These features do not change the .NET execution model so much as reorganize code syntax and reduce some repetitive boilerplate. Their value is particularly apparent in projects that use collection expressions, work with nested loops, or need more concise access interfaces for extensible types.
However, the features are still in preview, so they do not yet represent a stable final interface. Microsoft invites developers to download .NET 11 and try C# 15 with their applications, while referring to the complete reference for what is new and participating in the ongoing discussions within the csharplang project. The source does not specify a final date for moving the features to a stable release in this article.