Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

384
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda