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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:38:46+00:00 2026-05-24T00:38:46+00:00

string[] names = {avinash,harish, savan, shyam }; foreach (var name in names) namesAll +=

  • 0
string[] names = {"avinash","harish", "savan", "shyam" };
foreach (var name in names)
    namesAll += name;

We know that string is immutable in .NET. Each time we concatenate a new string to an existing string, a new memory location is reserved which contains the new concatenated string…which is pointed to by the string reference. This seems fine to me.

What stumps me is why should the the location of the string reference (namesAll) also change? To me this seems completely unnecessary. You can ascertain this in Visual Studio using the Memory window to look at the location of the string reference (namesAll).

Here’s the address of namesAll after each iteration: 0x01ef9594 0x01ef961c 0x01ef9644 Please note, this is not the address of the concatenating string (which will obviously change), but the address of the string reference namesAll.

  • 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-24T00:38:47+00:00Added an answer on May 24, 2026 at 12:38 am

    A specific string will get a reference that is reused anywhere the string is used. Changing the value referenced will change all these other locations as well, hardly what you want…

    As a new string is created in each iteration, a new string gets a new memory location – this is referenced by the variable, hence the new address.

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

Sidebar

Related Questions

D2.056 void f(string[] names...) { foreach (name; names) { mixin(string ~ name ~ =
I have a string as follows: names = name:fred, name:wilma, name:barney, name2:gauss, name2:riemann let's
public void displayData(String [] names, int []scores, char [] grades){ for (String name :
I have a string array: string[] names; I want to remove all names that
Say I have a list of names. case class Name(val first: String, val last:
How do I turn a string into a class name, but only if that
How to sort string names in array on ascending order . I tried sort
I have the following code: // Obtain the string names of all the elements
Follow up to this question . I have the following code: string[] names =
I have a string of names like this J. Smith; B. Jones; O. Henry

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.