I am working with arrays and need to sort the array. This array keeps showing out of range exceptions
<p>I have established an array and a large textbox which displays the array.  Basically, you enter a name, 4 quarterly sales figures and it calculates the yearly total.  I am now starting on the sort button.  This would sort given columns numbers from most to least.  I have gotten an if statement that looks like it should work for column five (the total column).  I keep getting an out of range exception and am not sure why.  Any ideas out there?  I am sure this is a simple problem I am not seeing. </p>

<pre><code>do {
    swapFlag = false;
    for (n=0; n &lt; lastIndexUsed; n++)
    {
         if (quarters[n, sortCol] &lt; quarters[n+1, sortCol])
         {
             //Column 5
             temp = quarters[n,5];
             quarters[n,5] = quarters[n +1, 3];
             quarters[n +1, 3] = temp;
             //swapflag
             swapFlag = true;
         }
    }
} while (swapFlag);
</code></pre>

<p>This shows how I get 0-5 for sortCol:</p>

<pre><code>if (rbRegion.Checked)
    sortCol = 0;

if (rb1.Checked)
    sortCol = 1;

if (rb2.Checked)
    sortCol = 2;

if (rb3.Checked)
    sortCol = 3;

if (rb4.Checked)
    sortCol = 4;

if (rbTotal.Checked)
    sortCol = 5;
</code></pre>

<p>Button Variables:</p>

<pre><code>int n;
int temp;
int sortCol = 0;
string ntemp;
bool swapFlag;
</code></pre>

<p>Global Variables</p>

<pre><code>int lastIndexUsed = -1;
int[,] quarters = new int[10, 5];
string[] Branch = new string[10];
</code></pre>
