StringBuilder Q

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Coming out from the VC++ Background I was trying to clear the Stringbuilder
object with sb.Length=0
Is this approach OK? If not what's the alternative, looks like I have run
into an exception when the size of the SB is gargantous!! like > 200MB

Please advice

TIA
 
Vai2000 said:
Coming out from the VC++ Background I was trying to clear the Stringbuilder
object with sb.Length=0
Is this approach OK? If not what's the alternative, looks like I have run
into an exception when the size of the SB is gargantous!! like > 200MB

Yup, that should be fine. You might want to consider creating a new
instance though instead - if you reuse a StringBuilder a lot, it will
end up getting promoted to later generations, which may not be a good
idea. (It then becomes more expensive to use, because changes to its
reference fields require more complicated operations to keep the GC
efficient.)
 
Vai2000 said:
Coming out from the VC++ Background I was trying to clear the Stringbuilder
object with sb.Length=0
Is this approach OK? If not what's the alternative, looks like I have run
into an exception when the size of the SB is gargantous!! like > 200MB

Similar cool trick: To delete the last character in a StringBuilder,
sb.Length--;

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top