Code inspection: Redundant 'object.ToString()' call
This inspection reports redundant ToString()
calls in two cases:
When you call it on an object of type
String
.When you call it in an argument of a method that implicitly calls
ToString()
on the corresponding parameter.
In both cases, the ToString()
call is redundant and can be safely removed to improve readability.
public void Test(object obj, string str, StringBuilder sb)
{
// 'str' is already of type 'String'
Console.WriteLine(str.ToString());
// 'StringBuilder.Append' calls 'ToString()' internally
sb.Append(obj.ToString());
}
Last modified: 05 June 2024