Skip to content

Gendarme.Rules.Performance.AvoidUnneededCallsOnStringRule(2.10)

Sebastien Pouliot edited this page Jan 22, 2011 · 2 revisions

AvoidUnneededCallsOnStringRule

Assembly: Gendarme.Rules.Performance
Version: 2.10

Description

This rule detects when some methods, like Clone(), Substring(0), ToString() or ToString(IFormatProvider), are being called on a string instance. Since these calls all return the original string they don't do anything useful and should be carefully reviewed to see if they are working as intended and, if they are, the method call can be removed.

Examples

Bad example:

public void PrintName (string name)
{
    Console.WriteLine ("Name: {0}", name.ToString ());
}

Good example:

public void PrintName (string name)
{
    Console.WriteLine ("Name: {0}", name);
}

Notes

  • Prior to Gendarme 2.0 this rule was more limited and named AvoidToStringOnStringsRule
Clone this wiki locally