C# 15 adds with() for collection constructor arguments
C# 15, shipping with .NET 11, introduces a with(...) element in collection expressions whose arguments go to the constructor or factory, such as a HashSet comparer. The feature is available in .NET 11 RC1, released September 8, 2026 with a go-live license.
- with(...) must be the first element inside the brackets
- Arguments are passed to the constructor or [CollectionBuilder] factory
- Arrays and spans reject with() with error CS9355
- Dictionary accepts a comparer but not KeyValuePair elements
Read next
Software