string.Fromat vs StringBuilder vs +

Posted on 2008-11-14
Last Modified: 2012-05-05
Which is more efficient:

1. string.Fromat("some text {0}", text)
2. Stringbuilder
3. concatinate using +
Question by:gustierng
    LVL 9

    Accepted Solution

    Stringbuilder is most efficient then String.format and finally +

    Why is stringbuilder more efficient than string.format? Its because string.format actually uses stringBuilder internally and the applies the formatting.

    + is the slowest as string is immutable, which means you have to create a new string object each time you change the value of a string variable

    LVL 26

    Expert Comment

    by:Anurag Thakur
    + will be the slowest operation and mentioned by amx and to further add on to what amx has to say please go through the following link
    LVL 69

    Expert Comment

    by:Éric Moreau
    LVL 19

    Expert Comment

    The comparison of methods depends on the situation.  It would be inaccurate to make such generalizations as "StringBuilder is fastest" and "+ operator is slowest".

    When you need to build a long string with multiple operations, this is certainly true.  If the desire is siimply to concatenate two existing strings, the + operator will be just as good, and potentially better.  If the desired result is something that can be accomplished by a single call to String.Format, then that will be just as efficient as Stringbuilder.  Since the Format method tries to make a guess as to the length of your result whereas the average programmer uses default construction, Format may actually outperform Stringbuilder.

    Bottom line is that you need to take into account your specific programming need before you can say which method is going to be most efficient.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now