Question: I'm beginner to c# programming. I'm going to make game in c#.In that case I want to color change when I click the picture box.this is my code

```
         private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
    {
        int[] R = { 0, 255, 255, 34, 249,255 };
        int[] G = { 0, 255, 0, 235, 255 ,153};
        int[] B= { 255, 255, 0, 27, 40,51 };
        pictureBox1.BackColor = Color.FromArgb(R[this.index], G[this.index], B[this.index]);
        this.index++;
      }

```

this code worked.when i click picturebox color changed.According to array R,G,B can get 6 colors.after the last color I got this message..
**Index was outside the bounds of the array.**

Please someone tell me solution for this.Thank you...

Answer: 
I found the way.

```
        int[] R = { 0, 255, 255, 34, 249, 255 };
        int[] G = { 0, 255, 0, 235, 255, 153 };
        int[] B = { 255, 255, 0, 27, 40, 51 };
        pictureBox2.BackColor = Color.FromArgb(R[this.index], G[this.index], B[this.index]);
        this.index++;
        if (this.index == 6)
        {
            this.index -= 6;

        }

```

after the 6th color.again we can get first color
Array index start from 0 and it's length is 6, therefore just wrap IF around your code something like this

```
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
   if(this.index <= 5){
    int[] R = { 0, 255, 255, 34, 249,255 };
    int[] G = { 0, 255, 0, 235, 255 ,153};
    int[] B= { 255, 255, 0, 27, 40,51 };
    pictureBox1.BackColor = Color.FromArgb(R[this.index], G[this.index], B[this.index]);
    this.index++;
    }
}

```