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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:16:24+00:00 2026-05-24T22:16:24+00:00

I have an List<string> that I am iterating through and splitting on each item

  • 0

I have an List<string> that I am iterating through and splitting on each item then adding it to a StringBuilder.

foreach(string part in List)
{
   StringBuilder.Append(part.Split(':')[1] + " ");
}

So my question is how many strings are created by doing this split? All of the splits are going to produce two items. So… I was thinking that it will create a string[2] and then an empty string. But, does it then create the concatenation of the string[1] + " " and then add it to the StringBuilder or is this optimized?

  • 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-24T22:16:25+00:00Added an answer on May 24, 2026 at 10:16 pm

    The code is actually equivalent to this:

    foreach(string part in myList)
    {
       sb.Append(string.Concat(part.Split(':')[1], " "));
    }
    

    So yes, an additional string, representing the concatenation of the second part of the split and the empty string will be created.

    Including the original string, you also have the two created by the call to Split(), and a reference to the literal string " ", which will be loaded from the assembly metadata.

    You can save yourself the call to Concat() by just Appending the split result and the empty string sequentially:

    sb.Append(part.Split(':')[1]).Append(" ");
    

    Note that if you are only using string literals, then the compiler will make one optimzation for you:

    sb.Append("This is " + "one string");
    

    is actually compiled to

    sb.Append("This is one string");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of string values that I want add to a hashtable
I have a string list (TStrings) that has a couple thousand items in it.
I have a list that has some chapter numbers in string. When I sort
I have a method that returns a list of type string. I want to
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have an XML file that contains an illegal character, I am iterating through
I have a List of strings that is regenerated every 5 seconds. I want
I have sorted list of strings that I move between php and java. to
Using bash, I have a list of strings that I want to use to
I have a list of 400 strings that all end in _GONOGO or _ALLOC.

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.