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

  • SEARCH
  • Home
  • 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 8385519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:41:28+00:00 2026-06-09T17:41:28+00:00

I have a StringBuilder object where I am adding some strings like follows: I

  • 0

I have a StringBuilder object where I am adding some strings like follows:

I want to know which one is better approach here, first one is this:

StringBuilder sb = new StringBuilder();
sb.Append("Hello" + "How" + "are" + "you");

and the second one is:

StringBuilder sb = new StringBuilder();
sb.Append("Hello").Append("How").Append("are").Append("you");
  • 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. Editorial Team
    Editorial Team
    2026-06-09T17:41:29+00:00Added an answer on June 9, 2026 at 5:41 pm

    The first will be more efficient. The compiler will convert it to the following single call:

    StringBuilder sb = new StringBuilder();
    sb.Append("HelloHowareyou");
    

    Measuring the performance

    The best way to know which is faster is to measure it. I’ll get straight to the point: here are the results (smaller times means faster):

    sb.Append("Hello" + "How" + "are" + "you")                  : 11.428s
    sb.Append("Hello").Append("How").Append("are").Append("you"): 15.314s
    sb.Append(a + b + c + d)                                    : 21.970s
    sb.Append(a).Append(b).Append(c).Append(d)                  : 15.529s
    

    The number given is the number of seconds to perform the operation 100 million times in a tight loop.

    Conclusions

    • The fastest is using string literals and +.
    • But if you have variables, using Append is faster than +. The first version is slower because of an extra call to String.Concat.

    In case you want to test this yourself, here’s the program I used to get the above timings:

    using System;
    using System.Text;
    
    public class Program
    {
        public static void Main()
        {
            DateTime start, end;
            int numberOfIterations = 100000000;
            start = DateTime.UtcNow;
            for (int i = 0; i < numberOfIterations; ++i)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Hello" + "How" + "are" + "you");
            }
            end = DateTime.UtcNow;
            DisplayResult("sb.Append(\"Hello\" + \"How\" + \"are\" + \"you\")", start, end);
    
            start = DateTime.UtcNow;
            for (int i = 0; i < numberOfIterations; ++i)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Hello").Append("How").Append("are").Append("you");
            }
            end = DateTime.UtcNow;
            DisplayResult("sb.Append(\"Hello\").Append(\"How\").Append(\"are\").Append(\"you\")", start, end);
    
            string a = "Hello";
            string b = "How";
            string c = "are";
            string d = "you";
    
            start = DateTime.UtcNow;
            for (int i = 0; i < numberOfIterations; ++i)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(a + b + c + d);
            }
            end = DateTime.UtcNow;
            DisplayResult("sb.Append(a + b + c + d)", start, end);
    
            start = DateTime.UtcNow;
            for (int i = 0; i < numberOfIterations; ++i)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(a).Append(b).Append(c).Append(d);
            }
            end = DateTime.UtcNow;
            DisplayResult("sb.Append(a).Append(b).Append(c).Append(d)", start, end);
    
            Console.ReadLine();
        }
    
        private static void DisplayResult(string name, DateTime start, DateTime end)
        {
            Console.WriteLine("{0,-60}: {1,6:0.000}s", name, (end - start).TotalSeconds);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing StringBuilder object, the code appends some values and a delimiter
Say I have a Song object like public Song(){ String artist, title; StringBuilder lyrics;
I have a StringBuilder object which I have built with comma seperated values, which
hello friends following is my query where displaylist is object if stringBuilder which have
Say I have a StringBuilder object var sb = new StringBuilder(); And an arbritrary
I don't know either my implementation have bugs or StringBuilder is going wrong. From
I have a Stringbuilder object that has been populated from a text file. How
i have an object which holds a user name and job count, which then
I have a list and i am adding a value using add(int,Object) method but
I am getting object reference error while putting string.format in stringbuilder. I have below

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.