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

  • Home
  • SEARCH
  • 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 1016639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:34:43+00:00 2026-05-16T10:34:43+00:00

How the StringBuilder class is implemented? Does it internally create new string objects each

  • 0

How the StringBuilder class is implemented? Does it internally create new string objects each time we append?

  • 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-05-16T10:34:44+00:00Added an answer on May 16, 2026 at 10:34 am

    In .NET 2.0 it uses the String class internally. String is only immutable outside of the System namespace, so StringBuilder can do that.

    In .NET 4.0 String was changed to use char[].

    In 2.0 StringBuilder looked like this

    public sealed class StringBuilder : ISerializable
    {
        // Fields
        private const string CapacityField = "Capacity";
        internal const int DefaultCapacity = 0x10;
        internal IntPtr m_currentThread;
        internal int m_MaxCapacity;
        internal volatile string m_StringValue; // HERE ----------------------
        private const string MaxCapacityField = "m_MaxCapacity";
        private const string StringValueField = "m_StringValue";
        private const string ThreadIDField = "m_currentThread";
    

    But in 4.0 it looks like this:

    public sealed class StringBuilder : ISerializable
    {
        // Fields
        private const string CapacityField = "Capacity";
        internal const int DefaultCapacity = 0x10;
        internal char[] m_ChunkChars; // HERE --------------------------------
        internal int m_ChunkLength;
        internal int m_ChunkOffset;
        internal StringBuilder m_ChunkPrevious;
        internal int m_MaxCapacity;
        private const string MaxCapacityField = "m_MaxCapacity";
        internal const int MaxChunkSize = 0x1f40;
        private const string StringValueField = "m_StringValue";
        private const string ThreadIDField = "m_currentThread";
    

    So evidently it was changed from using a string to using a char[].

    EDIT: Updated answer to reflect changes in .NET 4 (that I only just discovered).

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

Sidebar

Related Questions

when we store more than one string in arraystring or in stringbuilder class objects.then
public class TextFileExtractor{ public static String[] fileExtractor(String[] s){ StringBuilder sb=new StringBuilder(); for(int i=0;i<=s.length;i++){ if(s[i].endsWith(.txt)){
I was curious how the StringBuilder class is implemented internally, so I decided to
Is there some string class in Python like StringBuilder in C#?
If I do: StringBuilder sb = new StringBuilder(); sb.append(somestring + hello + more strings
I'm trying to use stringbuilder to create a body of string to be used
After reading the android documentation about String, which includes this: This class is implemented
Why does StringBuffer/StringBuilder does not override the equals() , hashcode() methods from object? Please
Can extensive StringBuilder.Append() operations be optimized by using char[] allocated on thread's stack to
I have the following: StringBuilder errors = new StringBuilder(); if(IsNullOrEmpty(value)) { errors.AppendLine(Enter value); }

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.