0

Possible Duplicate:
String vs StringBuilder

In VB.NET, is it better to use string concatenation or StringBuilder when concatenating large amount of strings?

Is there any performance issue or memory issue because of this?

Community
  • 1
  • 1
trelston
  • 633
  • 1
  • 5
  • 13
  • A few more dupes for you: stackoverflow.com/questions/550702, stackoverflow.com/questions/1612797, stackoverflow.com/questions/21078, stackoverflow.com/questions/73883, – p.campbell May 27 '11 at 16:00
  • Repeating the dupes with http prefix so that StackOverflow shows the questions as linked: http://stackoverflow.com/questions/550702, http://stackoverflow.com/questions/1612797, http://stackoverflow.com/questions/21078, http://stackoverflow.com/questions/73883 – MarkJ May 27 '11 at 16:01

1 Answers1

1

You should use whatever is more readable to humans, performance gain is pretty inrelevant in this case. Optimize later, ater you used profiler to measure your code and optimize just critical parts.

Look at this link : The Sad Tragedy of Micro-Optimization Theater

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
  • 1
    -1 I disagree. I you are concatenating an unknown and potentially large number of strings together you definitely should use a StringBuilder. This is not premature optimization; this is writing code that performs better than the alternative at literally no cost in terms of readability or maintainability. – Ed S. May 27 '11 at 16:11
  • @Ed S. It so hard to know when this performace difference will be actually noticable or important, and IMO such code is realy rare btw. I did not say that one should not use StringBuilder :) – Antonio Bakula May 27 '11 at 19:01
  • But you in effect called this premature/micro optimization, which it is not. It is simply the right thing to do in this scenario. Premature optimization is optimizing when no clear need has been demonstrated and in such a way that negatively affects the readability and/or maintainability of the code. In this case you are simply using the right tool for the job. – Ed S. May 27 '11 at 21:09