• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assigning array references

 
Arthur Blair
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... reading the K+B book.

If you assign an array to a previously declared array reference, the array you're assigning must be the same dimension as the reference you're assigning it to.

so why does this compile corectly?



What am I doing wrong here?
Thoughts appreciated.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your arrays are of a different size, not of a different dimension. They are all one dimensional int arrays. The dimension of an array is the number of indexes required to locate an element.
 
David Rowland
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"dimensions" refers to the number of sets of brackets the array has, to put it simply.

int[] oneDimensional = new int[x][y]; //illegal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic