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 7410495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:14:33+00:00 2026-05-29T06:14:33+00:00

Possible Duplicate: Why is String.Concat not optimized to StringBuilder.Append? One day I was ranting

  • 0

Possible Duplicate:
Why is String.Concat not optimized to StringBuilder.Append?

One day I was ranting about a particular Telerik control to a friend of mine. I told him that it took several seconds to generate a controls tree, and after profiling I found out that it is using a string concatenation in a loop instead of a StringBuilder. After rewriting it worked almost instantaneously.

So my friend heard that and seemed to be surprised that the C# compiler didn’t do that conversion automatically like the Java compiler does. Reading many of Eric Lippert’s answers I realize that this feature didn’t make it because it wasn’t deemed worthy enough. But if, hypothetically, costs were small to implement it, what rationale would stop one from doing it?

  • 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-05-29T06:14:34+00:00Added an answer on May 29, 2026 at 6:14 am

    But if, hypothetically, costs were small to implement it, what rationale would stop one from doing it?

    It sounds like you’re proposing a bit of a tautology: if there is no reason to not do X, then is there a reason to not do X? No.

    I see little value in knowing the answers to hypothetical, counterfactual questions. Perhaps a better question to ask would be a question about the real world:

    Are there programming languages that use this optimization?

    Yes. In JScript.NET, we detect string concatenations in loops and the compiler turns them into calls to a string builder.

    That might then be followed up with:

    What are some of the differences between JScript .NET and C# that justify the optimization in the one language but not in the other?

    A core assumption of JScript.NET is that its programmers are mostly going to be JavaScript programmers, and many of them will have already built libraries that must run in any implementation of ECMAScript. Those programmers might not know the .NET framework well, and even if they do, they might not be able to use StringBuilder without making their library code non-portable. It is also reasonable to assume that JavaScript programmers may be either novice programmers, or programmers who came to programming via their line of business rather than a course of study in computer science.

    C# programmers are far more likely to know the .NET framework well, to write libraries that work with the framework, and to be experienced programmers who understand why looped string concatenation is O(n2) in the naive implementation. They need this optimization generated by the compiler less because they can just do it themselves if they deem it necessary.

    In short: compiler features are about spending our budget to add value for the customer; you get more "bang for buck" adding the feature to JScript.NET than you do adding it to C#.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Stringbuilder vs String.Concat As I understand it, String are immutable, so if
Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat?
Possible Duplicate: String vs StringBuilder I just revisited some of the books that I
Possible Duplicate: Last but one Char in vb.net String How do I find the
Possible Duplicate: If string only contains spaces? I do not want to change a
Possible Duplicate: String vs StringBuilder i know .NET Strings are immutable which is the
Possible Duplicate: java String concatenation StringBuilder vs String concatenation in toString() in Java I
Possible Duplicate: C# String output: format or concat? what is the benefit of using
Possible Duplicate: String vs StringBuilder Hi, I'm creating a json string. I have some
Possible Duplicate: random string generation - two generated one after another give same results

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.