← back to index

S2360 — Optional parameters should not be used

Language: C#  |  Type: CODE_SMELL  |  Severity: Critical

Tags: pitfall

Why is this an issue?

The overloading mechanism should be used in place of optional parameters for several reasons:

Noncompliant code example

void Notify(string company, string office = "QJZ") // Noncompliant
{
}

Compliant solution

void Notify(string company)
{
  Notify(company, "QJZ");
}
void Notify(string company, string office)
{
}

Exceptions

The rule ignores non externally visible methods.