Why does this fix the issue w/ my Jagged array?
<p>Small preface, I'm not a pro- programmer, I'm actually a mechanical engineer who happens to know <em>some</em> programming, and this is my First question here, so please bear with me. I'm kind of just putting rough summary code instead of my actual code to keep things simple.</p>

<p>I have a jagged array in vb.net that i'm using to track how much of some given compounds are going through each "zone" where the zones are the first index of the jagged array. I've already initialized the array elsewhere with:</p>

<pre><code>jagged_arr()() = new double(4)() {}
</code></pre>

<p>and the first of the arrays is always set beforehand, ex:</p>

<pre><code>jagged_arr(0) = {1, 2, 3, 4}
</code></pre>

<p>So later on I'm trying to iterate through and process things on a zone by zone basis, essentially:</p>

<pre><code>for z = 0 to 3
  if z = 2
    jagged_arr(z + 1) = jagged_arr(z)  'NOTE!!!

    for r = 0 to jagged_arr(z + 1).getUpperBound(0)
      'more calcs
      jagged_arr(z + 1)(r) += 2
    next
  end if
next
</code></pre>

<p>Instead of giving me the array i expect:</p>

<pre><code>{{1, 2, 3, 4},
 {1, 2, 3, 4},
 {3, 4, 5, 6},  
 {3, 4, 5, 6},
 {3, 4, 5, 6}}
</code></pre>

<p>I get an array like this:</p>

<pre><code>{{3, 2, 3, 4},
 {3, 2, 3, 4},
 {3, 4, 5, 6},
 {3, 4, 5, 6},
 {3, 4, 5, 6}}
</code></pre>

<p>I'm pretty confused why that happened. I'm even more confused why it worked as intended after i replaced the line noted above (with NOTE!!!) with this:</p>

<pre><code>jagged_array(z + 1) = new double(jagged_array(z).getUpperBound(0)) {}
for i = 0 to jagged_array(z + 1).getUpperBound(0)
  jagged_array(z + 1)(i) = jagged_array(z)(i)
next
</code></pre>

<p>Am I missing something here? I don't get why having each array initially copy the last is causing this odd behavior. Any help is appreciated!</p>