

String declaration in iteration - silverappy

Hi there,<p>This morning a was writing a piece of code and it made me wonder what the best possible way is to write this code.<p>Because a string is immutable in .NET, is it really that bad to create a new instance for each iteration?<p>Your thoughts on this please.<p>*For a short code illustration, check out http://silverappy.wordpress.com/2011/04/21/string-declaration-in-iteration/
======
gus_massa
If myArray is large (maybe >10), you should use a StringBuilder. But
optimization is tricky and YMMV.

Some article about this (for a few strings)
[http://www.codinghorror.com/blog/2009/01/the-sad-tragedy-
of-...](http://www.codinghorror.com/blog/2009/01/the-sad-tragedy-of-micro-
optimization-theater.html)

And a simmilar question in SO:
[http://stackoverflow.com/questions/21078/whats-the-best-
stri...](http://stackoverflow.com/questions/21078/whats-the-best-string-
concatenation-method-using-c)

I think that StackOverflow (<http://stackoverflow.com>) is a better site to
get answers to this kind of questions

~~~
silverappy
Thanks gus!

