-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Performance.AvoidConcatenatingCharsRule(2.10)
Sebastien Pouliot edited this page Feb 9, 2011
·
3 revisions
Assembly: Gendarme.Rules.Performance
Version: 2.10
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.
Bad 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 + ']');
}
Good 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 () + "]");
}
- This rule is available since Gendarme 2.8
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!