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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:06:27+00:00 2026-06-08T19:06:27+00:00

I need to store different quantities of values in an int[] array, depending on

  • 0

I need to store different quantities of values in an int[] array, depending on how many items have been selected from my CheckboxList control (cblSections).

At the moment I’m storing these values in an ArrayList, then determining the length of this object, and setting the size of my int[] object dependant on that.

Is there a better way of doing this, which involves less code (and less objects!)?

ArrayList alSectionId = new ArrayList();
foreach (ListItem item in cblSections.Items) {
    if (item.Selected) {
        alSectionId.Add(item.Value);
    }
}

int[] sectionId = new int[(alSectionId.Count - 1) + 1];

if (alSectionId.Count > 0) {
    int i = 0;
    foreach (int sId in alSectionId) {
        sectionId[i] = sId;
        i += 1;
    }
}
  • 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-08T19:06:28+00:00Added an answer on June 8, 2026 at 7:06 pm

    You should use the List object instead. Then once you have populated this you can covert it directly to an int[] using the ToArray() function:

    List<int> items = new List<int>();
    items.ToArray();
    

    NOTE: Although the ArrayList class does also seem to have a ToArray() function, it is better to use List anyway… why? I have no idea, it’s one of those things I have heard so many times that I just take it for granted and forget the original reason why :/

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

Sidebar

Related Questions

I need to store 150 different tiny integer values (range from 0 to 7)
I need to store different table markup code in a php array, as a
I have id values for products that I need store. Right now they are
I need to store reviews from different sources in table. Fields: 'produtcId' char(14) 'user'
I need to store data related to items where there will be various different
I need to store two items per array element — two arrays of char
I have a requirement to store dates and durations arising from multiple different calendars.
I have a following problem: I need to store generic objects with different type
I need to store different versions of not very long strings for different languages
I'm using the great jquery-file-upload image uploader, but need to store images for different

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.