C# Collection Expression vs Collection Initializer
Compare C# collection expressions and collection initializers: syntax, type inference, span support, and when to use each.

When you initialize a collection in C#, the collection initializer has been the standard syntax since C# 3.0. The collection expression, introduced in C# 12, offers a shorter form and changes how the compiler resolves the target type. Choosing between the two matters when you adopt a syntax in new code or migrate existing initialization sites.
The Two Syntaxes Side by Side
A collection initializer creates a new instance and populates it with elements:
List<int> numbers = new List<int> { 1, 2, 3 };The collection expression removes the explicit constructor call:
List<int> numbers = [1, 2, 3];The target type is supplied by the assignment context, so the same expression can target an array, a list, a span, or an interface:
int[] array = [1, 2, 3];
List<int> list = [1, 2, 3];
Span<int> span = [1, 2, 3];
IEnumerable<int> sequence = [1, 2, 3];A collection initializer cannot target Span<int> or IEnumerable<int> directly because it requires a concrete type with an accessible Add method. Collection expressions target a broader set of types: arrays, spans, interfaces such as IEnumerable<T>, and collection types the compiler can construct through the collection initializer pattern or a CollectionBuilder attribute.
How Type Inference Differs
Collection initializers always require an explicit target type because the syntax is tied to the constructor call. Collection expressions are target-typed: the compiler determines the concrete type from the assignment context. This makes them usable in return statements, method arguments, and switch expressions where a collection initializer would need a temporary variable.
static int[] BuildValues() => [10, 20, 30];The target-typed nature also means the same literal can be passed directly to a method parameter without an intermediate variable. This reduces noise in call sites that previously required a local collection.
Using the Spread Operator to Combine Collections
Collection expressions introduce the spread operator .., which expands an existing collection into the new one:
int[] first = [1, 2];
int[] second = [3, 4];
int[] combined = [.. first, .. second, 5];The resulting array contains 1, 2, 3, 4, 5. The spread operator works with any enumerable source, including LINQ results, and the compiler copies the elements into the target collection. A collection initializer has no equivalent syntax; combining collections required calling AddRange or looping over the source.
Span Support and Allocation Behavior
A significant difference between the two syntaxes is how they interact with stack-allocated memory. A collection expression can target Span<T> and ReadOnlySpan<T>:
Span<int> values = [1, 2, 3];In simple local declarations, the compiler can often build the span without a heap allocation when the element count is known at compile time. A collection initializer cannot produce a span at all, because it depends on instance construction and Add calls. If you need a temporary buffer for a short-lived operation, a collection expression can avoid allocating a List<int> or array on the managed heap. The exact allocation behavior depends on the target type and the surrounding context, so measure in a hot path rather than assuming a guarantee.
Compatibility and Language Version Requirements
Collection expressions require C# 12 or later. The syntax itself is a compiler feature, so it works with older .NET runtimes for most target types. Span targets, however, depend on System.Span<T>, which requires .NET Core 2.1+ or the System.Memory package on .NET Framework. Collection initializers work in every C# version since 3.0 and have no runtime dependency beyond the type's Add method.
When a codebase targets multiple language versions, the project file's <LangVersion> setting controls whether collection expressions compile. A team standardizing on C# 12 can adopt the new syntax, while a library that must compile under older language versions should keep collection initializers.
Choosing Between Collection Expression and Collection Initializer
Use a collection expression when the target type is an array, span, or a common collection type such as List<T>, and when the element set is known at the call site. The syntax is shorter, works in more contexts, and supports the spread operator.
Keep the collection initializer when the project does not use C# 12 or when you prefer the explicit new form for custom collection types. A custom type that supports the collection initializer pattern can also be used with a collection expression. For example, a NameCollection with an Add(string) method and an IEnumerable<string> implementation can be initialized with either syntax. A custom type that has no suitable Add method can opt in with a CollectionBuilder attribute.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# Dispose vs Destructor: Key Differences Explained
c# dispose vs destructor: Understand the difference between Dispose and destructors in C#, when each runs, and how to manage unmanaged resources correctly.
C# Variable Declaration: Syntax and Practical Usage
Learn how to declare variables in C# with explicit types, var, and nullable annotations, and understand how defaults, scope, and readability affect your choices.
C# Primary Constructors for Classes: Syntax and Usage
Learn how to use C# primary constructors for classes: syntax, initialization, dependency injection, and limitations with practical examples.
C# IComparer: Custom Sorting with IComparer<T>
Learn how to implement IComparer<T> in C# to define custom sort order for arrays and lists, handle nulls, and avoid common performance pitfalls.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.