Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 118655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:31:45+00:00 2026-05-11T03:31:45+00:00

Possible Duplicate: String vs StringBuilder I just revisited some of the books that I

  • 0

Possible Duplicate:
String vs StringBuilder

I just revisited some of the books that I used to pick up VB.NET. I am not sure I’ve got this in my head, understand how/what StringBuilder is.

What is the guidance for using? Is it best to use it if you are are concatenating 2 strings or 50?

Or when the the total string length is greater than 128 characters?

Or will you see a performance benefit whenever you use it to add strings together?

In which case is it better to use a StringBuilder instance to build a SQL statement than string.format('Select * from x where y = {0}',1)?

It’s always struck me that declaring another variable and including a name space is not beneficial for small string concatenations, but I am not sure now.

Sorry, lot of documentation tells you what to use, just not what’s best.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:31:45+00:00Added an answer on May 11, 2026 at 3:31 am

    I’ve got an article on this very topic. In summary (copied from the bottom of the page):

    • Definitely use StringBuilder when you’re concatenating in a non-trivial loop – especially if you don’t know for sure (at compile time) how many iterations you’ll make through the loop. For example, reading a file a character at a time, building up a string as you go using the += operator is potentially performance suicide.
    • Definitely use the concatenation operator when you can (readably) specify everything which needs to be concatenated in one statement. (If you have an array of things to concatenate, consider calling String.Concat explicitly – or String.Join if you need a delimiter.)
    • Don’t be afraid to break literals up into several concatenated bits – the result will be the same. You can aid readability by breaking a long literal into several lines, for instance, with no harm to performance.
    • If you need the intermediate results of the concatenation for something other than feeding the next iteration of concatenation, StringBuilder isn’t going to help you. For instance, if you build up a full name from a first name and a last name, and then add a third piece of information (the nickname, maybe) to the end, you’ll only benefit from using StringBuilder if you don’t need the (first name + last name) string for other purpose (as we do in the example which creates a Person object).
    • If you just have a few concatenations to do, and you really want to do them in separate statements, it doesn’t really matter which way you go. Which way is more efficient will depend on the number of concatenations the sizes of string involved, and what order they’re concatenated in. If you really believe that piece of code to be a performance bottleneck, profile or benchmark it both ways.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: most elegant way to return a string from List<int> I'm not sure
Possible Duplicate: String equality vs equality of location I just got my first assessed
Possible Duplicate: LINQ to append to a StringBuilder from a String[] Forgive my functional
Possible Duplicate: .NET String to byte Array C# How do I convert String to
Possible Duplicate: Split string, convert ToList<int>() in one line… i have a string that
Possible Duplicate: Split string in SQL I have seen a couple of questions related
Possible Duplicate: Escape string for use in Javascript regex I have a msg like
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I
Possible Duplicate: Why do I get a segmentation fault when writing to a string?
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.