Skip to main content
The params keyword is a parameter modifier in C# that enables a method to accept a variable number of arguments of a specified type. When invoked, the compiler automatically aggregates the provided comma-separated values into a single-dimensional array (or, starting in C# 13, other supported collection types) and passes it to the method’s execution context.

Invocation Mechanics

The compiler handles params arguments by dynamically generating the underlying collection at the call site. You can invoke a params method in three distinct ways:

Architectural Rules and Constraints

  • Positioning: The params parameter must be the absolute last parameter in the formal parameter list. Signatures like void Method(params int[] numbers, string text) will result in a compiler error (CS0231).
  • Multiplicity: A method signature can declare a maximum of one params parameter.
  • Type Requirements: Prior to C# 13, the params type was strictly limited to single-dimensional arrays (e.g., int[], object[]). C# 13 introduced params collections, which builds upon the C# 12 collection expression infrastructure to allow params to be applied to types like Span<T>, ReadOnlySpan<T>, List<T>, and IEnumerable<T>.
  • Mutually Exclusive Modifiers: A params parameter cannot be combined with in, ref, or out modifiers.
  • No Default Values: A params parameter cannot be assigned a default value in the method signature. Declarations such as params string[] args = null will result in a compiler error.
  • Nullability: If the caller omits the params arguments entirely, the compiler injects an empty array (or empty span/collection), guaranteeing the parameter is not null. However, a caller can explicitly pass null (e.g., ProcessData(100, null)), which will result in a null reference inside the method.
  • Overload Resolution Precedence: During method binding, the C# compiler prioritizes exact signature matches over params expansions. If Method(int, string) and Method(int, params string[]) both exist, calling Method(1, "A") will bind to the exact match, bypassing the array allocation overhead of the params overload.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More