when can I use StringBuilder over String Type?

Hi Experts,

I'm confusing when to use string builder over String Type.

I Think If i'm doing more concatenation operations , it is preferable to use StringBuilder.

Can anybody tell me , the performance issues regarding usage of stringbuilder.

Thanks In advance.




Answer this question

when can I use StringBuilder over String Type?

  • Alex Yakhnin - MSFT

    Thank u boban

    then when the no of concatenations are more than 5 , it is better to use StringBuilder . Am I right



  • wls1973

  • Asifkhan75025

    Hello,

    if the concatenations are more than 5, use StringBuilder.... this is the example rule of boban...The same way you can define your own rule and see what is best for you. If there are more number of modifications on the string, it is better to use StringBuilder.



  • chxfryer

    There is no defined rule when to use string concatenation versus StringBuilder. Working with StringBuilder not always give's you performance. My rule is when i have loop in which i concatenate or modify strings then i use StringBuilder, but when i know that number of loops will be higher than 5 for example. Also i try always to specify Capacity of StringBuilder when possible.

  • biw

    Yes, you are right. One should use StringBuilder if there is number of concatenations. This will give you better performance compare to using "+" with string type.

    Following explains about StringBuilder

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconusingstringbuilderclass.asp

    Hope this helps you!!!!



  • when can I use StringBuilder over String Type?