rspec/rules/S3450/csharp/rule.adoc

28 lines
570 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
There is no point in providing a default value for a parameter if callers are required to provide a value for it anyway. Thus, ``++[DefaultParameterValue]++`` should always be used in conjunction with ``++[Optional]++``.
== Noncompliant Code Example
----
public void MyMethod([DefaultParameterValue(5)] int j) //Noncompliant, useless
{
Console.WriteLine(j);
}
----
== Compliant Solution
----
public void MyMethod(int j = 5)
{
Console.WriteLine(j);
}
----
or
----
public void MyMethod([DefaultParameterValue(5)][Optional] int j)
{
Console.WriteLine(j);
}
----