<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up" -->

---
title: Refactor your code with C# collection expressions
description: Learn how to refactor your C# code using collection expressions, a simple and consistent syntax for initializing collections. Collection expressions provide a...
canonical: https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Refactor your code with C# collection expressions | daily.dev
og:description: Learn how to refactor your C# code using collection expressions, a simple and consistent syntax for initializing collections. Collection expressions provide a...
og:url: https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up
og:image: https://api.daily.dev/og/posts/Ki81he5uP.png
og:image:alt: Refactor your code with C# collection expressions
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Refactor your code with C# collection expressions

**[DevBlogs](https://daily.dev/sources/devblogs)** · 9 min read · 18 upvotes · 1 comments

## Summary

Learn how to refactor your C# code using collection expressions, a simple and consistent syntax for initializing collections. Collection expressions provide a readable and maintainable way to initialize collections of various types, including arrays and lists. They offer advantages such as consistent initialization syntax, efficient code generation, and support for interfaces and empty collections. Explore different scenarios where collection expressions can be used and understand the semantic considerations when using this new syntax.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://devblogs.microsoft.com/dotnet/refactor-your-code-with-collection-expressions>

## Community discussion

Top comments from developers on daily.dev.

**@ashy** · 0 upvotes

> It's nice that they are consistently adding features purely for readability. And the empty initialization seems to be a nod towards javascript, which if using both on a project is really nice to use similar syntax for initiating empty collections.

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Refactor your code with C# collection expressions","url":"https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up"},"datePublished":"2024-05-08T17:06:32.279Z","dateModified":"2024-05-09T08:20:02.615Z","description":"Learn how to refactor your C# code using collection expressions, a simple and consistent syntax for initializing collections. Collection expressions provide a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/abc1a0f5159ce48f41a4995b457a37e7?_a=AQAEuiZ","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/abc1a0f5159ce48f41a4995b457a37e7?_a=AQAEuiZ","isAccessibleForFree":true,"articleSection":"DevBlogs","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"DevBlogs","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/8f68b453325f482ebeb73fb780092713","url":"https://daily.dev/sources/devblogs"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":18},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"c#","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DevBlogs","item":"https://daily.dev/sources/devblogs"},{"@type":"ListItem","position":3,"name":"Refactor your code with C# collection expressions"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/refactor-your-code-with-c-collection-expressions-ki81he5up","comment":[{"@type":"Comment","text":"It’s nice that they are consistently adding features purely for readability. And the empty initialization seems to be a nod towards javascript, which if using both on a project is really nice to use similar syntax for initiating empty collections.","datePublished":"2024-05-09T18:52:13.109Z","url":"https://daily.dev/posts/Ki81he5uP#c-9VqAAS4qX","author":{"@type":"Person","name":"Ashy","url":"https://daily.dev/ashy","image":"https://media.daily.dev/image/upload/s--SBTGLkDl--/f_auto/v1715027616/avatars/avatar_9CGpkpOpsrxrzI78zt6br"}}]}
```

