ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Redundant explicit collection creation in argument of 'params' parameter

Last modified: 05 June 2024

In C#, methods can be defined with a variable parameter list indicated by the params keyword before the last parameter. When invoking these methods, the arguments can be listed directly in the method call, or as an array of elements of the appropriate type.

This inspection reports cases where you are explicitly creating an array for a params argument instead of simply listing the arguments. This explicit array creation is redundant and can be simplified without changing the program's behavior.

Taking into account the signature of the String.Join() method — public static string Join(string separator, params string[] value), the example below illustrates how the redundant array creation can be removed to clarify the code.