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

  • Home
  • SEARCH
  • 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 8310897
In Process

The Archive Base Latest Questions

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

Techies– This code works when I have a single channel or when I have

  • 0

Techies–
This code works when I have a single channel or when I have an even split. It almost works when I have a remainder…in that it will create the next channel and it will pull in the item, but then goes out of range. These lines are the heart of the trouble:

    items_per_batch = batchcount / (int)channels; //
    subsets = batch.Split(items_per_batch); 

items_per_batch is really used to give the Split extension an idea of a general number on how many items to split by. If it sees a remainder, it just creates another subset array. What i really need to do is keep track of the length of items. I tried:

    int idx2 = subset.GetLength(1) 

At one point, but the forloop using that value also went out of range. Anyone have any suggestions?

    static void channelassign()
    {
        int THRESHOLD = 2;
        string[] batch = new string[]
        { "item1", "item2", "item3", "item4","item5","item6","item7" };
        int batchcount = batch.Count();
        int items_per_batch;
        string[][] subsets;
        int idx1;
        int idx2;


        if (THRESHOLD != 0) //avoid accidental division by 0.
        {

            float channels = batchcount / THRESHOLD;
            if (channels < 1)
            {
                channels = 1; // only 1 channel is needed
                items_per_batch = batchcount; // process all items
                idx1 = 1; // fix value to a single channel
                idx2 = (batchcount - 1); // true start of array is 0
                subsets = batch.Split(batchcount); //splits correctly
            }
            else
            {
              // decide how many items will be included per batch
              channels =  (int)Math.Round(channels, 
                  MidpointRounding.ToEven); //determines channel number
              items_per_batch = batchcount / (int)channels; //
              subsets = batch.Split(items_per_batch); 
              idx1 = subsets.GetLength(0); // gets channel# assigned by split
              // idx2 = subsets.GetLength(1); // gets items back from splits

            }

            //distribute contents of batch amongst channels


            for (int channel = 0; channel < idx1; channel++)
            {
                for (int i = 0; i < items_per_batch; i++)
                {
                    Console.WriteLine(" Channel:" + channel.ToString() + " 
                       ItemName: {0} ", subsets[channel][i]);
                }
            }


        }
        else
        {
            Console.WriteLine("Threshold value set to zero. This 
               is an invalid value. Please set THRESHOLD.");
        }
  • 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:37:39+00:00Added an answer on June 8, 2026 at 7:37 pm

    The division

    float channels = batchcount / THRESHOLD;
    

    is performed on ints, so your float channels always has an integer value, equal to

    floor(batchcount / THRESHOLD)
    

    But that’s not the cause of your problem, that is

    for (int channel = 0; channel < idx1; channel++)
    {
        for (int i = 0; i < items_per_batch; i++)
    

    that if batchcount is not a multiple of channels, some channels have fewer than items_per_batch items. Thus the inner loop then tries to access a subsets[channel][i] that doesn’t exist.

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

Sidebar

Related Questions

Does anyone have an XSLT that will take the app.config and render it into
Techies-- I think I'm defining this static extension correctly for Split, I obviously am
I need to daily run a script that will download a file from a
For example if I have a web page HTML like below <body> Hello Techies,
I understand this is purely a coding related forum, but i believe techies can
Hai Techies, I have some stored procedure which was written in SQL server.Now i
I want the matched results to be highlighted. This works for me if I
My Techie Bretheren (and Sisteren, of course!), I have a LinqToSql data model that
I'd like to provide a browser page to help non-techies run the various tests
I have an unordered list, and I'm attempting to append a few links to

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.