string.Fromat vs StringBuilder vs +

Which is more efficient:

1. string.Fromat("some text {0}", text)
2. Stringbuilder
3. concatinate using +
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anurag ThakurTechnical ManagerCommented:
+ 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
Éric MoreauSenior .Net ConsultantCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.