S2360 — Optional parameters should not be used

Language
VB.NET
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


Sub Notify(ByVal Company As String, Optional ByVal Office As String = "QJZ") ' Noncompliant

End Sub

Compliant solution


Sub Notify(ByVal Company As String)
  Notify(Company, "QJZ")
End Sub

Sub Notify(ByVal Company As String, ByVal Office As String)

End Sub

Exceptions

The rule ignores non externally visible methods.

↑ Back to top