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

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer expected Solution: enum defination: public enum Status { CLOSED(1), NEW(2),… May 13, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer The biggest difference in this specific case is that iabbr… May 13, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer Changing your sub to use print and purge instead of… May 13, 2026 at 8:53 am

Related Questions

So I'm getting a new job working with databases (Microsoft SQL Server to be
So, in your experience, whats the best way? Is there a secure way that's
So our web server apps need to connect to the database, and some other
So I have a Sybase stored proc that takes 1 parameter that's a comma
So I'm embarking on an ASP.NET MVC project and while the experience has been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.