Gendarme.Rules.Performance.AvoidConcatenatingCharsRule Class
This rule will warn you if boxing is used to concatenate a string since this will slow down your code and can be easily avoided. This often happen when concatenating System.String and System.Char values together. However the rule is not limited to check boxing on System.Char since compilers often transform a character into its integer value (e.g. 'a' == 61) and the same boxing issue exists on integers.

See Also: AvoidConcatenatingCharsRule Members

Syntax

[Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine, Gendarme.Framework, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null))]
[Gendarme.Framework.Problem("Unneeded boxing was found for concatening a string.")]
[Gendarme.Framework.Solution("Change your code to avoid the boxing when creating your string.")]
public class AvoidConcatenatingCharsRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule

Remarks

This rule is available since Gendarme 2.8

Example

Bad example:

Example

            public string PrintIndex (string a, char b)
            {
            	// This is compiled into String.Concat(params object[])
            	// and requires boxing the 4 characters
            	Console.WriteLine ('[' + a + ',' + b + ']');
            }
            

Example

Good example:

Example

            public string PrintIndex (string a, char b)
            {
            	// This is compiled into String.Concat(params string[])
            	// and no boxing is required
            	Console.WriteLine ("[" + a + "," + b.ToString () + "]");
            }
            

Requirements

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