What does the params keyword do?
Quick Answer
params lets a method accept a variable number of arguments as an array: void Log(params string[] parts) can be called as Log("a", "b", "c") or Log(array). It must be the last parameter, and each call with loose arguments allocates a new array.
params on the last parameter lets callers pass any number of arguments and the compiler bundles them into an array — so void Log(params object[] args) can be called with two arguments or five. It's what makes string.Format and Console.WriteLine work. The thing to know is that calling it with separate arguments allocates a fresh array every time, so in performance-sensitive code I'd add explicit overloads. Newer C# lets params target a span to avoid that.
- Convenience for APIs like
string.Format,Console.WriteLine,Path.Combine. - Calling it with individual arguments allocates an array each time — in a hot path, provide overloads for 1–3 args or accept a collection.
- C# 13 adds
paramsforReadOnlySpan<T>and other collection types, avoiding the allocation. - You can pass an existing array directly — no double-wrapping.