# What's new in C# 15: Collection expression arguments

Square brackets made lists short to write, until you needed a setting like "ignore upper and lower case". C# 15 lets you pass that setting inside the brackets.

By Gregor Dzierzon · Published November 15, 2026

![Codey holds a clipboard titled Newsletter sign-up with three emails on it, two of them the same address in different capitals](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/c5233a74251b48cbbcb75a64d31a612e.webp)

> **What's new in C# 15**
>
> 1. [The release: .NET 11, LTS and STS](https://www.ask-codey.com/blog/whats-new-in-csharp-15)
> 2. [Union types](https://www.ask-codey.com/blog/whats-new-in-csharp-15-union-types)
> 3. [Labeled `break` and `continue`](https://www.ask-codey.com/blog/whats-new-in-csharp-15-labeled-break-and-continue)
> 4. [Closed hierarchies](https://www.ask-codey.com/blog/whats-new-in-csharp-15-closed-hierarchies)
> 5. **Collection expression arguments**
> 6. Extension indexers
> 7. For library authors: static interface members on older runtimes, and memory safety
>
> [All posts in this series](https://www.ask-codey.com/blog?tag=csharp-15)

## Collection expression arguments

Say you're building a newsletter sign-up list. Sam signs up twice: once as `Sam@Example.com` and once as `sam@example.com`. To a person, that's the same email. You want one copy, not two.

A `HashSet<string>` keeps only one copy of each value, so it's the right collection. And since C# 12, you can fill one with a **[collection expression](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions)**, the short square-bracket form:

```csharp
HashSet<string> emails = ["Sam@Example.com", "sam@example.com", "ana@example.com"];
```

But this set holds **three** emails. A `HashSet` compares strings exactly, letter for letter, and an uppercase `S` isn't a lowercase `s`.

### The problem: no room for settings

![A box labeled HashSet holds three cards: Sam@Example.com, sam@example.com and ana@example.com; Codey says to a person those first two are the same email](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/38f95deaed3647b1bff29dcea4a240b9.webp)

The fix is to give the set a different way to compare: `StringComparer.OrdinalIgnoreCase`, a ready-made comparer that ignores upper and lower case. You pass it when the set is created, to its **constructor**. Until now, a collection expression had nowhere to put it, so you had to go back to the long form:

```csharp
HashSet<string> emails = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
    "Sam@Example.com", "sam@example.com", "ana@example.com"
};
```

It works. But it means one style when a collection needs a setting and another when it doesn't, for no good reason.

### The C# 15 answer: `with(...)` first

C# 15 lets the first item in the brackets be **`with(...)`**, holding whatever you'd pass to the constructor:

```csharp
HashSet<string> emails = [with(StringComparer.OrdinalIgnoreCase), "Sam@Example.com", "sam@example.com", "ana@example.com"];
```

Read it out loud as **"a set, made with a comparer that ignores case, holding these emails."** It holds two emails: Sam once, and Ana.

![A big pair of square brackets holds a settings card, with: ignore upper and lower case, followed by email cards; the two Sam cards merge into one, and the result reads 2 emails, as Codey points at the settings card](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/8c4a0ac867d54042a207299f983d6080.webp)

### Another everyday use: capacity

![On the left, a small shelf being replaced by a bigger one with boxes being moved across, labeled Without capacity: build bigger and copy, again and again; on the right, one long shelf labeled capacity: 1000, and Codey says know how many are coming? make room once](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/3e00d236410a478ab259f50bb659059b.webp)

A `List<T>` stores its items in an array. When the array fills up, the list makes a bigger one and copies everything over. If you already know a list will hold about a thousand orders, you can give it room for that many from the start, its **capacity**, so it never has to stop and copy:

```csharp
List<string> orderIds = [with(capacity: 1000), .. todaysOrders];
```

The `..` spreads the items of `todaysOrders` into the new list. The list holds today's orders and has room for a thousand.

### Good to know

- **`with(...)` must come first** in the brackets.
- **It doesn't work for arrays or spans,** which have no constructor settings to pass.
- **Without `with(...)`, nothing changes.** Every collection expression you've written still works the same way.

It's a small feature. Its value is that a collection expression now covers the cases where you used to give up and write the long form.

**On one page:** [the collection expression arguments cheat sheet](https://www.ask-codey.com/cheat-sheets/csharp-15-collection-expression-arguments-cheat-sheet), to keep or to share.

## Sources

- Microsoft, [Collection expressions](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions), Microsoft Learn: collection expressions and `with(...)` arguments, with their rules.
- Microsoft, [What's new in C# 15](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-15), Microsoft Learn: every C# 15 feature, with examples.

Tags: [csharp](https://www.ask-codey.com/blog?tag=csharp), [csharp-15](https://www.ask-codey.com/blog?tag=csharp-15), [dotnet](https://www.ask-codey.com/blog?tag=dotnet), [whats-new](https://www.ask-codey.com/blog?tag=whats-new)

## Glossary subjects

- [C#](https://www.ask-codey.com/glossary/subjects/c-sharp)

## More posts

- Previous: [What's new in C# 15: Closed hierarchies](https://www.ask-codey.com/blog/whats-new-in-csharp-15-closed-hierarchies)

Source: https://www.ask-codey.com/blog/whats-new-in-csharp-15-collection-expression-arguments
