Gendarme.Rules.Performance.CompareWithEmptyStringEfficientlyRule Class
This rule will fire if a string is compared to "" or String.Empty.
Instead use a String.Length test which should be a bit faster. Another
possibility (with .NET 2.0) is to use the static String.IsNullOrEmpty method.
String.IsNullOrEmpty.
[Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine, Gendarme.Framework, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null))] [Gendarme.Framework.FxCopCompatibility("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")] [Gendarme.Framework.Problem("This method compares a string with an empty string by using the Equals method or the equality (==) or inequality (!=) operators.")] [Gendarme.Framework.Solution("Compare String.Length with 0 instead. The string length is known and it's faster to compare integers than to compare strings.")] public class CompareWithEmptyStringEfficientlyRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule
Remarks
Documentation for this section has not yet been entered.
Example
Bad example:
Example
public void SimpleMethod (string myString)
{
if (myString.Equals (String.Empty)) {
}
}
Example
Good example:
Example
public void SimpleMethod (string myString)
{
if (myString.Length == 0) {
}
}
Requirements
Namespace: Gendarme.Rules.Performance Assembly: Gendarme.Rules.Performance (in Gendarme.Rules.Performance.dll) Assembly Versions: 2.8.0.0