2

I don't know why I'm experiencing so much trouble with this, but I would like to have an array that basically represents a layer number and x,y coordinates so I could essentially say,

int i = array[layer,x,y] and get the corrisponding value per layer. I create the array..

int[,,] myarray

...initialize it

 myarray = new int[0,width, height];

...and it blows up when try and grab a value.

int n = myarray[0,1,1]

What am I missing?

3 Answers 3

3

You are initializing an array with 0 as a length. Use 1:

myarray = new int[1,width, height];
Sign up to request clarification or add additional context in comments.

Comments

2
myarray = new int[0,width, height]; 

You just told the computer that the length of the first dimension of the array is 0. Basically, your array can hold nothing.

In C#, the value you use in the array declaration indicates the length of the dimension. It's different than if you are coming from a language such as Visual Basic, where the value indicates the upper bound.

Dim array(4) as Integer

Array of 5 integer elements in VB

int[] array = new int[4];

Array of 4 integer elements in C#

Comments

1

Try using a non-zero value for the first array dimension.

Comments

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.