Parameters variables that are not marked as out
or ref
should not be assigned to from within a method.
Those modifications will not impact the caller of the method, which can be confusing.
Instead, it is better to assign the parameter to a temporary variable.
The following code snippet:
void foo(int a) { a = 42; // Non-Compliant }
should be refactored into:
void foo(int a) { int tmp = a; tmp = 42; // Compliant }
or:
void foo(out int a) // 'ref' is also allowed { a = 42; // Compliant }