Back
Close

The Difference between String and StringBuilder in C#

AramT
54.2K views

The equation to know the size of String in memory, for a Unicode string with a maximum length of 2,147,483,647 characters, is as follows:

80 + [16 * Length] bits

Example:

string stringSample = "Tech.io" //7 Characters

Then using the string equation:

80 + (16 * 7) = 192 Bits

Same equation divided by 8, will get us the size in bytes:

(10 + [2 * Length] bytes) = 10 + (2 * 7) = 24 Bytes

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io