Pattern: Missing use of strongly-typed Append()
/Insert()
Issue: -
Append
and Insert
provide overloads for multiple types beyond String
. When possible, prefer the strongly-typed overloads over using ToString()
and the string-based overload.
Example of incorrect code:
class Test
{
int _value;
public void Log(StringBuilder destination)
{
destination.Append("Value: ").Append(_value.ToString()).AppendLine();
}
}
Example of correct code:
class Test
{
public void Log(StringBuilder destination)
{
destination.Append("Value: ").Append(_value).AppendLine();
}
}