Start Debugging
2025-01-02 Updated 2026-11-02 csharp-13csharpdotnetdotnet-9 Edit on GitHub

C# 13: Use params collections with any recognized collection type

C# 13 permits params collections beyond arrays. See element arguments, normal versus expanded calls, supported collection shapes and allocation caveats.

This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process

C# 13 extends params beyond one-dimensional arrays to recognized collection types. The expanded call passes individual elements, not a variable number of spans.

Correction — November 2, 2026: corrected the element-versus-span explanation and collection requirements. Passing a list to an ordinary IEnumerable<T> parameter was already possible before C# 13. Both examples below were checked with SDK 10.0.302 and LangVersion 13.

Span parameters

using System;

Print(1, 2, 3); // Expanded form: three int elements.
int[] data = { 4, 5 };
Print(data);    // Normal form: an existing buffer.

static void Print(params ReadOnlySpan<int> values)
{
    foreach (int value in values)
        Console.WriteLine(value);
}

The normal form passes an existing value convertible to the declared parameter type. The expanded form supplies elements from which the compiler constructs the parameter collection. A ReadOnlySpan<T> parameter can avoid an array allocation in suitable calls; this is not an allocation-free guarantee for every type or call.

Which collections qualify?

Supported shapes include Span<T>, ReadOnlySpan<T>, the recognized generic collection interfaces, and collection-expression-compatible builder types. Constructible collection types need the required accessible parameterless constructor and suitable instance Add method, along with enumeration support. Implementing IEnumerable<T> and merely having any method named Add is not sufficient.

The supported interfaces include IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T> and IList<T>.

using System;
using System.Collections.Generic;

var values = new List<int> { 1, 2, 3 };
Print(values);  // Normal form.
Print(4, 5, 6); // Expanded form: enabled by params collections in C# 13.

static void Print(params IEnumerable<int> values)
{
    foreach (int value in values)
        Console.WriteLine(value);
}

The first call did not need this language feature: a non-params IEnumerable<int> parameter also accepts the list in older C#. C# 13 adds the expanded Print(4, 5, 6) form for that parameter type. Constructing an interface-backed collection for an expanded call can allocate.

Keep params last, do not give it a default value, and do not combine it with ref, in or out. Adding a params-collection overload can change overload resolution when callers recompile; check your API’s actual call sites.

For the difference between owning a collection and viewing its storage, see List, Span and ReadOnlySpan.

Sources

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.