JavaScript Editor Ajax toolkit     Ajax website 

Main Page

The plus operator is a slow way to concatenate strings. Consider using System.Text.StringBuilder instead.

The plus (+) operator concatenates strings. In many circumstances, such as appending many small strings to another string, System.Text.StringBuilder produces code that runs much faster.

For example, consider the following code that builds the string "0123456789". It generates this warning when compiled.

В CopyCode imageCopy Code
var a : String = "";
for(var i=0; i<10; i++)
   a += i;

When run, this displays the string "0123456789".

When the previous example uses System.Text.StringBuilder, the program runs faster and does not generate the warning.

В CopyCode imageCopy Code
var b : System.Text.StringBuilder;
b = new System.Text.StringBuilder();
for(var i=0; i<10; i++)

Like the program before, this also displays "0123456789".

Another way to prevent the warning from being displayed is to use an untyped variable to hold the string to which other strings are appended.

To correct this error

  1. Use System.Text.StringBuilder for the type of the string to which other strings are appended, and rewrite the statements with the += operations to use the Append method instead.

  2. Use an untyped variable for the string to which other strings are appended. (This solution will not make the code run faster, but it will suppress the warning.)

See Also


StringBuilder Class


Troubleshooting Your Scripts

Other Resources

JScript Reference

JavaScript Editor Ajax toolkit     Ajax website