1

when trying to use a loop to create a jagged array, but what happens is I get an IndexOutOfRangeException when i and j are 0. Here is the code

        double[,][] coords = new double[,][] { };
        for (int i = 0; i <= p; i++)
        {
            for (int j = 0; j <= q; j++)
            {
                coords[i, j] = new double[4] { (4 things in here) };
            }
        }

I have read this: http://www.daniweb.com/software-development/java/threads/360615 but do not know how to apply it to this.

Solution: changed from "double[,][] coords = new double[,][] { };" to "double[,][] coords = new double[p,q][];" Thanks!

1
  • What are you trying to achieve? How are p and q initialized? Commented Dec 22, 2011 at 1:22

1 Answer 1

3

You need to instantiate your array size, from your code I assume this would be correct size.

double[,][] coords = new double[p+1,q+1][];
Sign up to request clarification or add additional context in comments.

2 Comments

+1 , and also he need change the i < = p and j < =q to i < p and j < q ?
I can't tell if he needs that, he should know, but if he does, array size will be just [p,q]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.