Collection Expression Arguments in C# 15+

1/12/2026
2 minute read

There is a nice proposal which would make collection expressions a bit better - Giving the users the ability to pass in arguments to the creation.


Info: This is based on the current discussion and issue on the dotnet/csharplang repository: [Proposal]: Collection Expression Arguments. It is currently a proposal and might come in C# 15 (or more likely) later or even never.


What are collection expressions?

As a very small recap: Collection expressions are a different syntax to create collections in C#:

List<int> evenNumbers = [2, 4, 6, 8, 10];
List<int> oddNumbers = [1, 3, 5, 7, 9];


// Merge two collections and a add a 0 at the beginning
List<int> allNumbers = [0, ..evenNumbers, ..oddNumbers];

Of course that doesn't only work with List<T>, but with any type that implements the right pattern. See more here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions

The advantage is: Having a concise syntax and maybe have a better performance characteristic in some cases (as the compiler can be smart about the usage).

But we can make it better!

Now im case of allNumbers the compiler would create a new List with the right capacity:

num2 = 1 + (list4.Count + list5.Count);
List<int> list6 = new List<int>(num2);

But there are cases where the compiler doesn't know, but you know how many elements will be in the collection (db call or whatnot). Right now, you don't have the opportunity to tell the list to be created with a specific capacity. But the proposal would allow to change that. Now as said earlier - that is a proposal and the syntax used in the follow example will not be final (as said in the issue: "strawman syntax"):

List<int> allNumbers = [args(capacity: 32), 0, ..evenNumbers, ..oddNumbers];

This would create a list with a capacity of 32 right away (not that this is useful, but you get the point). This would translate to: new List<int>(32);. There are other things where this might come in handy. For example HashSet<T> allows to pass in an IEqualityComparer<T>. In the following case for string comparison:

HashSet<string> names = [args(comparer: StringComparer.OrdinalIgnoreCase), "Alice", "Bob", "alice"];
An error has occurred. This application may no longer respond until reloaded.Reload x