Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
StringBuilder vs Span<string> in C#

What is the difference between StringBuilder and Span<string> in C#?

Is the same code used in StringBuilder as in Span<string>?

If yes, then what is the difference between them, and if not, which one is better?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

StringBuilder grows to any size as you insert characters, while Span<> only ever points to a pre-allocated, fixed buffer. It will never grow.

The other two questions are just nonsense.

Edit: I will point out that there is an internal ValueStringBuilder that works on a span (and thus has a fixed maximum size), but is much more efficient within its limitations.

over 4 years ago · Santiago Trujillo Report

0

These are different. Each string is an array of characters. In the definition of a normal string, an array is defined and if you want to make any other changes, another array is defined and as a result, another memory is allocated, but the StringBuilder comes and creates a final array. This explanation was very simple and concise and without details, which is complete here

In the source code of StringBuilder, you can also see that it is using the same common types and don't work on the structure.

Span is a ref struct that is a completely different type and that is why it is not used everywhere.

Of course, Span is not only used for string. It can be done for any other immutable type. FMI

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!