.NET collections and C# collection expressions
Short answer
Use a collection expression to create common collection values. (S2)
List<int> nums = [1, 2, 3];
int[] all = [.. nums, 4, 5]; // spread
Key points
- They don't require that you cast to and from the Object type when you add or remove items from the collection. (S1)
- You can't use collection expressions to initialize inline arrays. (S2)
Claims
- id: C1 claim: In general you should use generic collections. source: S1 evidence: "In general, you should use generic collections."
- id: C2 claim: System.Collections.Concurrent provides thread-safe collection operations. source: S1 evidence: "provide efficient thread-safe operations for accessing collection items"
- id: C3 claim: A collection expression is a terse syntax for many collection types. source: S2 evidence: "A collection expression is a terse syntax that you can assign to many different collection"
- id: C4 claim: A spread element .. inlines collection values. source: S2 evidence: "Use a spread element .. to inline collection values in a collection expression."
Sources
- [S1] Collections and Data Structures - .NET. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/standard/collections/ . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
- [S2] Collection expressions (Collection literals) - C# reference. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (.NET docs), Collections and Data Structures - .NET, CC BY 4.0 (dotnet/docs); Microsoft Learn (.NET docs), Collection expressions (Collection literals) - C# reference, CC BY 4.0 (dotnet/docs).
Cite this
iinventedlight. 2026. ".NET collections and C# collection expressions." iinventedlight Library, iil:note:qn0zt3m8, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-collections/. License: CC-BY-4.0.
@misc{iil_note_qn0zt3m8,
author = {{iinventedlight}},
title = {{.NET collections and C\# collection expressions}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/csharp-collections/},
note = {Permanent ID iil:note:qn0zt3m8. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/csharp-collections.md.