Jon
Wed Jul 21 16:19:17 CDT 2004
Oleg Sobol <morda31@yahoo.com> wrote:
> The question I have concerns string objects and how they are executed by
> CLR. Based on an article written in 2002 (last updated Dec 2003)
>
http://www.codeproject.com/dotnet/strings.asp , it is more advisable to
> use StringBuilder class than the String object to manipulate strings in
> Net because StringBuilder is more optimized. So, I was wondering if
> there had been any optimizations made to String object in Framework 1.1,
> and how it compares to StringBuilder? And also if there are more
> optimizations on the way in 2005 version of the Framework?
It's not so much because StringBuilder is optimised as because using a
StringBuilder means you don't have to create as many strings. It tends
to be handy if you're concatenating more than about 5-10 times (as
lower than that, the "effort" of creating the StringBuilder outweighs
the creation of the extra strings - although of course it depends on
exactly your situation.
I'm not sure that StringBuilder is actually handled particularly
differently by the CLR/JIT, btw - the reason it can modify strings is
because it's in mscorlib, so has access to the internal methods of
string which can modify it.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too