
org.sonar.plugins.csharp.S3450.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonarlint-omnisharp-plugin Show documentation
Show all versions of sonarlint-omnisharp-plugin Show documentation
Code Analyzer based on Omnisharp
Why is this an issue?
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);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy