Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

383
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda