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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:27:44+00:00 2026-06-02T21:27:44+00:00

Looking at the string class metadata, I only see the operators == and !=

  • 0

Looking at the string class metadata, I only see the operators == and != overloaded. So how is it able to perform concatenation for the ‘+‘ operator?

Edit:

Some interesting notes from Eric Lippert on string concatenation:

Part 1

Part 2

There is also a super article from Joel referred in part 2 (http://www.joelonsoftware.com/articles/fog0000000319.html)

  • 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-02T21:27:51+00:00Added an answer on June 2, 2026 at 9:27 pm

    It doesn’t – the C# compiler does 🙂

    So this code:

    string x = "hello";
    string y = "there";
    string z = "chaps";
    string all = x + y + z;
    

    actually gets compiled as:

    string x = "hello";
    string y = "there";
    string z = "chaps";
    string all = string.Concat(x, y, z);
    

    (Gah – intervening edit removed other bits accidentally.)

    The benefit of the C# compiler noticing that there are multiple string concatenations here is that you don’t end up creating an intermediate string of x + y which then needs to be copied again as part of the concatenation of (x + y) and z. Instead, we get it all done in one go.

    EDIT: Note that the compiler can’t do anything if you concatenate in a loop. For example, this code:

    string x = "";
    foreach (string y in strings)
    {
        x += y;
    }
    

    just ends up as equivalent to:

    string x = "";
    foreach (string y in strings)
    {
        x = string.Concat(x, y);
    }
    

    … so this does generate a lot of garbage, and it’s why you should use a StringBuilder for such cases. I have an article going into more details about the two which will hopefully answer further questions.

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

Sidebar

Related Questions

I'm looking for fast string concatenation class or so in Flex. Like StringBuilder in
I am looking for a class or method that takes a long string of
I was looking as the question : Instantiate a class from its string name
If I have a class, Foo, looking like this... class Foo { public string
I have a string looking like: some+thing+-+More How do i replace the + sign?
I am looking for the code for the c++ string class. What header is
I'm looking into overloading the + operator for a certain string so I was
I am looking for some efficient way for building a immutable class, just like
I was just looking at the implementation of the Java String class's .indexOf() method
I am looking for a utility class that can generate random certificate strings for

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.