← back to index

S2225 — "ToString()" method should not return Nothing

Language: VB.NET  |  Type: BUG  |  Severity: Major

Tags: cwe

Why is this an issue?

Calling ToString() on an object should always return a string. Thus, overriding the ToString method should never return Nothing because it breaks the method’s implicit contract, and as a result the consumer’s expectations.

Public Overrides Function ToString() As String
    Return Nothing ' Noncompliant
End Function
Public Overrides Function ToString() As String
    Return ""
End Function

Resources

Documentation