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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:03:54+00:00 2026-05-11T21:03:54+00:00

My below Codes gives me error:Index was outside the bounds of the array. My

  • 0

My below Codes gives me error:”Index was outside the bounds of the array.” My Algorithms create Colorset arrays that’s arrays dimention ’16’,
But i need Second one ‘colorSetLegend’ that’s dimensions:32 if you look below Bold codes that returns me error.

 Color[] colorSetLegend = new Color[32];
            Color[] colorSet = { Color.Red, Color.Blue, Color.Green, Color.Yellow };
            Color end = Color.White;
            colorSet = ColorMaker.GenerateColor(colorSet, end);

            for (int i = 0; i < colorSet.Length; )
            {
                for (int j = 0; j < colorSetLegend.Length; )
                {
                    colorSetLegend[j] = colorSet[i];
                    colorSetLegend[j++] = Color.Black;
                    i++;
                }
            }

My Color generator below:


public class ColorMaker
{
    public static Color[] GenerateColor(Color[] baseColorSet, Color end)
    {
        Color[] colorSet = new Color[16];
        int j = 0;
        foreach (Color start in baseColorSet)
        {
            for (int i = 0; i < 15; i += 4)
            {
                int r = Interpolate(start.R, end.R, 15, i),
                    g = Interpolate(start.G, end.G, 15, i),
                    b = Interpolate(start.B, end.B, 15, i);

                colorSet[j] = Color.FromArgb(r, g, b);
                j++;
            }
        }

        return colorSet;

    }
    static int Interpolate(int start, int end, int steps, int count)
    {
        float s = start, e = end, final = s + (((e - s) / steps) * count);
        return (int)final;
    }
}
  • 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-11T21:03:54+00:00Added an answer on May 11, 2026 at 9:03 pm

    You’re incrementing i in your inner loop. I suspect you meant to do it in your outer loop – otherwise during one iteration of your outer loop, you’re incrementing i many times, until you exceed the bounds of the array.

    Alternatively, you could write your for loops the same way everyone else does:

    for (int i = 0; i < colorSet.Length; i++)
    {
        for (int j = 0; j < colorSetLegend.Length; j++)
        {
            colorSetLegend[j] = colorSet[i];
            colorSetLegend[j] = Color.Black;
        }
    }
    

    Having said that, the code’s a bit pointless given that the first line inside the loop sets colorSetLegend[j] and the second line sets the same element again. Furthermore, on the next iteration of the outer loop you’ll be overwriting all the values in colorSetLegend all over again. What are you trying to accomplish?

    Marc made a good-looking guess at your aim here (although he’s now deleted his answer!)

    Here’s his guess at working code for what you want:

    for (int i = 0; i < colorSet.Length; i++)
    {
        colorSetLegend[i*2] = colorSet[i];
        colorSetLegend[(i*2)+1] = Color.Black;
    }
    

    A few things to learn from this, if he’s right:

    • Think about the level of nesting of your loops. Did you really mean to have two loops here?
    • Try to use conventional idioms for looping – whenever I see an empty bit at the end of the start of a for loop, I get nervous
    • Using pre- and post-increment operators in another expression is easy to get wrong.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the code below gives compilation error when I try to create test t[2]; because
I don't know why but this code below gives this error in debug mode
My code that I will post below gives me this error and I can't
Below code gives this error message Specified method is not supported. But here is
This below codes give me error below: How to generate this codes help me
The code below gives an error: Property 'Int32 Key' is not defined for type
The code below gives me this mysterious error, and i cannot fathom it. I
The code below gives me the following error: incompatible types when assigning to type'char[10]'
these below codes give whole data of my Rehber datas. But if i want
The code below gives me error = Subscript indices must either be real positive

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.