Gendarme.Rules.Performance.PreferCharOverloadRule Class
This rule looks for calls to String methods that use String parameters when a Char parameter could have been used. Using the Char overload is preferred because it will be faster. Note, however, that this may result in subtly different behavior on versions of .NET before 4.0: the string overloads do a culture based comparison using CultureInfo.CurrentCulture and the char methods do an ordinal comparison (a simple compare of the character values). This can result in a change of behavior (for example the two can produce different results when precomposed characters are used). If this is important it is best to use an overload that allows StringComparison or CultureInfo to be explicitly specified see [http://msdn.microsoft.com/en-us/library/ms973919.aspx#stringsinnet20_topic4] for more details. With .NET 4.0 String's behavior will change and the various methods will be made more consistent. In particular the comparison methods will be changed so that they all default to doing an ordinal comparison.

See Also: PreferCharOverloadRule Members

Syntax

[Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine, Gendarme.Framework, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null))]
[Gendarme.Framework.Problem("This code is calling a string-based overload when a char-based overload could be used.")]
[Gendarme.Framework.Solution("Replace the string parameters with chararacter parameters.")]
public class PreferCharOverloadRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

This rule is available since Gendarme 2.4

Example

Bad example:

Example

            if (s.IndexOf (":") == -1) {
            	Console.WriteLine ("no separator found");
            }
            

Example

Good example:

Example

            if (s.IndexOf (':') == -1) {
            	Console.WriteLine ("no separator found");
            }
            

Requirements

Namespace: Gendarme.Rules.Performance
Assembly: Gendarme.Rules.Performance (in Gendarme.Rules.Performance.dll)
Assembly Versions: 2.8.0.0