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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:19:01+00:00 2026-05-13T07:19:01+00:00

So…I have this scenario where I have a Foreach loop that loops through a

  • 0

So…I have this scenario where I have a Foreach loop that loops through a List of Checkboxes to check which are selected. For every selected checkbox, I have to do a pretty long string concatenation, involving 30 different strings of an average length of 20 characters, and then send it out as a HTTP request. 2 of the strings are dependant on the index/value of the checkbox selected.

The length of the List of Checkboxes is also variable depending upon the user’s data. I would say the average length of the List would be 20, but it can go up to 50-60. So the worst case scenario would be performing the whole string concatenation 60 or so times.

For now I’m doing it with simple string concatenation via the ‘+’ operator, but I’m wondering if it would be faster to do it with Stringbuilder. Of course, that means I’d have to either create a Stringbuilder object within the loop, or create it before the loop and call Stringbuilder.Remove at the end of it after sending out the HTTP request.

I appreciate any insights anybody can share regarding this issue.

EDIT
Thanks for all the replies everybody, so from what I’ve gathered, the best way for me to go about doing this would be something like:

 StringBuilder sb = new StringBuilder();
 foreach (CheckBox item in FriendCheckboxList)
 {
     if (item.Checked)
     {
         sb.Append(string1);
         sb.Append(string2);
         sb.Append(string3);
         .
         .
         .
         sb.Append(stringLast);

         SendRequest(sb.ToString());
         sb.Length = 0;
      }
  }
  • 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-13T07:19:01+00:00Added an answer on May 13, 2026 at 7:19 am

    Use StringBuilder. That’s what it’s for.

    Strings are immutable. String concatenation creates a new string, needing more memory, and is generally considered slow:

    string a = "John" + " " + "Saunders";
    

    This creates a string “John “, then creates another string “John Saunders”, then finally, assigns that to “a”. The “John ” is left for garbage collection.

    string a = "John";
    a += " ";
    a += "Saunders";
    

    This is about the same, as “John” is replaced by a new string “John “, which is replaced by a new string “John Saunders”. The originals are left to be garbage collected.

    On the other hand, StringBuilder is designed to be appended, removed, etc.


    Example:

    StringBuilder sb = new StringBuilder();
    for (int i=0; i<n; i++)
    {
        sb.Length = 0;
        sb.Append(field1[i]);
        sb.Append(field2[i]);
        ...
        sb.Append(field30[i]);
        // Do something with sb.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I see that some rss on xml have strange strings. For example, ... is
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
what about this one: I want to format the currentTime displayed by a videoPlayer
I have been making a wordpress template. i got stuck at some place... the
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
When I use the list function: el_nino_1974_2000_all <- list() for (k in seq_along(el_nino_start_month)){ el_nino_1974_2000_all[[k]]
I want to run this <!-- This will remove the tag --> <xsl:template name=remove-html>

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.