代码检查:具有默认值的冗余参数
此检查会识别代码中调用具有 可选参数的方法,并使用与这些参数的默认值相同的值的地方。
以下是一个示例:
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?
如果是前者,那么具有默认值的可选参数可以且应该被移除,因为默认值可能会在声明中发生更改。 否则,您可以通过注释 抑制此检查:
// ReSharper disable RedundantArgumentDefaultValue
最后修改日期: 2025年 9月 27日