3D array in Unity script (javascript) + debuging

I just started using Unity and I’ve run into little bit of hurdle.
I wanted to make 3D array to store state of cellular automaton, a task which was trivial in C++, unfortunately despite my best efforts the script throws
IndexOutOfRangeException: Array index is out of range.
(wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
array.Start () (at Assets/array.js:6)
error. While I understand what error means I don’t understand while following code

public var mat:int[,,] = new int[100,100,100];
function Start () {
for(var x : int = 0; x < mat.Length; x++){
for(var z : int = 0; z < mat.Length; z++){
for(var y : int = 0; y < mat.Length; y++){
mat[x,z,y] = binRandom();
}
}
}
}
function binRandom(){
var n;
var x = Random.Range(0.0, 1.0);
if (x < 0.5){
n = 1;
}
if (x > 0.5){
n = 0;
}
return n;
}

produces it.

Somewhat related to that is trouble I’ve been having with Monodevelop debugger.

When I attach it to unity editor and then run the game the entire application freezes and process has to be terminated. I have been following instruction from Unity manual so I don’t know where the problem is.

Thank you for replies.

Multi-demintion array matter Length as work of all internal arrays. In your case of Length = 100100100. And of course you receive a mistake as, for example, the element mat[100100, 100100, 100*100] doesn’t exist. Change a code a little:

 public var mat:int[,,] = new int[100,100,100];
 
 function Start () {
  //Sequentially for array x, z, y
  for(var x : int = 0; x <= mat.GetUpperBound(0); x++) {
   for(var z : int = 0; z <= mat.GetUpperBound(1); z++) {
    for(var y : int = 0; y <= mat.GetUpperBound(2); y++) {
     mat[x,z,y] = binRandom();
    }
   }
  }
 }

I hope that it will help you.