CA1025: Replace repetitive arguments with params array
Visual Studio 2010
TypeName | ReplaceRepetitiveArgumentsWithParamsArray |
CheckId | CA1025 |
Category | Microsoft.Design |
Breaking Change | Non-breaking |
Use a parameter array instead of repeated arguments when the exact number of arguments is unknown and the variable arguments are the same type, or can be passed as the same type. For example, the WriteLine method provides a general-purpose overload that uses a parameter array to accept any number of Object arguments.
The following example shows a type that violates this rule.
using System; namespace DesignLibrary { public class BadRepeatArguments { // Violates rule: ReplaceRepetitiveArgumentsWithParamsArray. public void VariableArguments(object obj1, object obj2, object obj3, object obj4) {} public void VariableArguments(object obj1, object obj2, object obj3, object obj4, object obj5) {} } public class GoodRepeatArguments { public void VariableArguments(object obj1) {} public void VariableArguments(object obj1, object obj2) {} public void VariableArguments(object obj1, object obj2, object obj3) {} public void VariableArguments(params Object[] arg) {} } }