Women in Technology

Hear us Roar



Article:
  StringBuilders Explained
Subject:   Calling ToString() on a StringBuilder
Date:   2003-07-28 05:36:29
From:   anonymous2
I read an article, written by Francesco Balena ("Speed Up Your VB.NET Code", Visual Studio Magazine), in which he says:
"For maximum performance, never reuse a StringBuilder object after you extract its contents with the ToString method, which returns the string in the internal buffer. Any other method would cause an additional memory allocation and copy operation to preserve the immutability of the returned string."


I notice that, in your example code, you call ToString() many times, in succession. Have you done any performance testing against storing the return from ToString() in a temp variable and referencing that, rather than calling ToString() over and over?


-Kevin Buchan