Skip to main content

How to Resolve Error "CS0225: The params parameter must have a valid collection type" in C#

The Compiler Error CS0225 is a syntax restriction error regarding the params keyword. The message reads: "The params parameter must be a single dimensional array" (in older versions) or "The params parameter must have a valid collection type" (in C# 13+).

In C#, the params keyword allows a method to accept a variable number of arguments (e.g., MyMethod(1, 2, 3, 4)). The compiler bundles these individual arguments into a collection before passing them to the method. Consequently, the parameter type you declare must be capable of holding that collection. Historically, this was strictly limited to single-dimensional arrays (e.g., int[]). As of C# 13, this has been expanded to other collections, but specific rules still apply.

This guide explains the requirements for params and how to fix invalid declarations.

Understanding the params Requirement​

When you call Sum(1, 5, 10), the compiler looks for a way to group 1, 5, and 10 together.

  • It needs a container.
  • Historically, that container must be declared as T[] (Array).
  • It cannot be just T (Single value).
  • It cannot be T[,] (Matrix/Multi-dimensional array).

Scenario 1: Forgetting the Array Syntax​

This is the most common cause. You want to accept multiple integers, but you declare the parameter as a single integer.

Example of error​

public class Calculator
{
// ⛔️ Error CS0225: The params parameter must be a single dimensional array.
// 'params int numbers' implies the compiler should stuff multiple inputs
// into a single integer variable, which is impossible.
public void Add(params int numbers)
{
// ...
}
}

Solution: Add Brackets []​

You must declare the parameter as an array.

public class Calculator
{
// ✅ Correct: 'int[]' creates a container for the arguments.
public void Add(params int[] numbers)
{
foreach (var n in numbers)
{
System.Console.WriteLine(n);
}
}
}

Scenario 2: Multi-dimensional Arrays​

The params keyword supports Jagged Arrays (int[][]), but it does not support Multi-dimensional Arrays (int[,]). The logic of "variable arguments" maps linearly to a list, not a grid.

Example of error​

public class GridProcessor
{
// ⛔️ Error CS0225: The params parameter must be a single dimensional array.
// You cannot pass a comma-separated list of arguments into a 2D matrix structure directly.
public void ProcessGrid(params int[,] grid)
{
}
}

Solution​

If you need to pass a 2D array, you cannot use params. You must pass the array explicitly.

public class GridProcessor
{
// ✅ Correct: Remove 'params'.
// The caller must manually create and pass the 'new int[,] { ... }'.
public void ProcessGrid(int[,] grid)
{
}
}

Scenario 3: Using Collections in Older C# Versions​

Prior to C# 13 (.NET 9), params was strictly limited to arrays. Using List<T> or IEnumerable<T> would trigger CS0225.

If you are using .NET 8, .NET Framework, or older:

Example of error (Pre-C# 13)​

using System.Collections.Generic;

public class Program
{
// ⛔️ Error CS0225 (in older versions): 'params' must be an array.
public void PrintNames(params List<string> names)
{
}
}

Solution: Use Arrays​

For maximum compatibility, stick to arrays.

public void PrintNames(params string[] names) { }

Modern Context (C# 13 / .NET 9+)​

If you have upgraded to the latest tools, the restrictions have been relaxed. You can now use params with types that support collection expressions (like List<T>, Span<T>, IEnumerable<T>).

// ✅ Correct (Only in C# 13+):
public void PrintNames(params IEnumerable<string> names) { }
public void PrintValues(params Span<int> values) { }
note

If you see CS0225 while using List<T>, check your LangVersion in the .csproj file. You likely need to upgrade to C# 13 or revert to using arrays.

Conclusion​

CS0225 ensures the compiler has a valid container to pack arguments into.

  1. Check Syntax: Did you forget the []? (e.g., use params int[] instead of params int).
  2. Check Dimensions: Ensure you aren't using [,] (multi-dimensional).
  3. Check Version: If trying to use params List<T>, ensure you are on C# 13+. Otherwise, convert to params T[].