Skip to content

C# Feature - Collection expression arguments

Collection expression arguments let you pass constructor or factory arguments into a collection expression by using a leading with(...) element.

This feature is documented as part of C# 15 preview. The official Microsoft Learn page is dated March 20, 2026 and says C# 15 preview is available with the .NET 11 preview SDK and Visual Studio 2026 Insiders.

Collection expressions already made collection creation concise. This feature extends that syntax so callers can still pass setup values such as capacity or comparers without falling back to more verbose construction code.

string[] values = ["one", "two", "three"];
List<string> names = [with(capacity: values.Length * 2), ..values];
HashSet<string> set = [with(StringComparer.OrdinalIgnoreCase), "Hello", "HELLO"];
  • Use it when collection expressions are the clearest representation and the target collection still needs constructor-like arguments.
  • Use it to preserve concise syntax without losing important collection configuration.
  • This feature is preview-only as of March 20, 2026.
  • Use it when the target collection is obvious; otherwise the syntax can feel too implicit.