rspec/rules/S2225/csharp/rule.adoc
2020-12-23 14:59:06 +01:00

36 lines
516 B
Plaintext

Calling ``ToString()`` on an object should always return a string. Returning ``null`` instead contravenes the method's implicit contract.
== Noncompliant Code Example
----
public override string ToString ()
{
if (this.collection.Count == 0)
{
return null; // Noncompliant
}
else
{
// ...
}
}
----
== Compliant Solution
----
public override string ToString ()
{
if (this.collection.Count == 0)
{
return string.Empty;
}
else
{
// ...
}
}
----
include::../see.adoc[]