Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:12:40+00:00 2026-06-02T23:12:40+00:00

I was going to post an answer on this other SO question but someone

  • 0

I was going to post an answer on this other SO question but someone went ahead of me with the StringBuilder class, anyways, digressing…

I understand that strings in .NET are immutable, so creating a string and modifying it will actually create two different strings in memory, contrary to the StringBuilder Class which maintains an internal buffer and creates a final string only on the ToString() call. I also know that .NET interns each string, so only a copy will be created per string ever used in the application.

When you append a string to another one they are both being used in the application, so they both get interned (don’t they?), the main reason for not to append strings with the concatenation operator is because you will end up with a whole bunch of strings in memory when done, each larger than the previous.

I understand that concatenating 01234 with 56789 will result in the following two strings in memory:

01234
0123456789

whilst using the StringBuilder will only yield, due to interning:

01234
56789

obviously the second approach is better for performance but, how good is it actually? I mean, if you’re creating a bigger string from a small list of values, why should I consider the StringBuilder (that per se takes memory space)? Is it always good to use it? Or is there any good rule of thumbs as to when [not] to use it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:12:56+00:00Added an answer on June 2, 2026 at 11:12 pm

    I also know that .NET interns each string

    No, you got the wrong idea about interning. When you create a new string by, say, concatenating then the runtime does not go hunting through the table of interned strings to see if there might be a match. That would be grossly inefficient, too many cpu cycles for a very modest savings in GC heap space.

    The only strings that are interned in a regular .NET app are the ones that started out as interned from the beginning. The ones that the compiler created from literals in your source code and added to the string table in the assembly metadata. You can explicitly intern a string with the String.Intern() method but that’s a very rare thing to do.

    You use StringBuilder to avoid generating too many temporary strings that have only a very short life span.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was going to post this on Database Administrators, but as it is slightly
I want to post a comment to this question's accepted answer, Haven't views abandoned
My original question I've managed to answer by cobbling other answers together from this
This is going to be a long post and just for fun, so if
I am going trough Facebook developer pages looking for right answer but all seems
I'm pretty sure the answer is going to be no here, but I just
I imagine this is a pretty hard question to answer without sitting down and
I just read this post about why new-line warnings exist, but to be honest
This is my first question here. I have been searching Stack Overflow and other
I know this type of question has been asked before, but I could not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.