Back
Close

The Difference between String and StringBuilder in C#

AramT
8,822 views
Previous: Benchmarking String vs StringBuilder Next: Conclusion

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
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants