ReSharper 2018.2 Help

Code Inspection: Redundant argument with default value

This inspection identifies places in your code where you call methods that have optional arguments, and use values that are identical to the default values for those arguments.

Here is an example:

void Foo(int required, [Optional] bool optionalBool, int optionalInt = 10) { // do something } void Test() { Foo(10, false, 10); //Warning: Redundant argument with default value }

The above call uses values identical to the default ones for both optional arguments, optionalBool and optionalInt, and this is somewhat ambiguous: is this call supposed to use the default values specified in the declaration of Foo() or, on the contrary, is it supposed to use the values specified by the caller independently of what the default values are?

If the former is the case, optional arguments with default values can and should be removed because the default values could change later in the declaration. Otherwise, you can just suppress this inspection with the comment:
// ReSharper disable RedundantArgumentDefaultValue

Last modified: 24 September 2018

See Also