title: IndexOutOfRangeException in multidimensional Arrays
body: <p>I have enclosed the code below, I was getting IndexOutOfRangeException not handled in Part A, then I tried Try-catch as below but now I am getting </p>
  
  <p><strong>"A first chance exception of type 'System.IndexOutOfRangeException' occurred in app.exe
     at app.Form6.ZMove(String s1, String s2) in C:\Users\Rahul Taneja\Documents\Visual Studio 2010\Projects\app\app\Form6.cs:line 136"</strong></p>
  
  <p>in stack trace</p>
  
  <p>can any one tell me why it is happening and what could be the solution?</p>
  
  <pre><code>public void ZMove(string s1, string s2)
          {
              //Move 2-1-4-3
              int j = Int32.Parse(s1);
              int k = Int32.Parse(s2);
              for (int l = 0; l &lt; k; l++)
              {
                  try
                  {
                      swap(array[2][j], array[1][j]); ///Part A
                      swap(array[1][j], array[4][j]);
                      swap(array[4][j], array[3][j]);
                      swap(array[3][j], array[2][j]);
                  }
                  catch (IndexOutOfRangeException e)
                  {
                      MessageBox.Show(e.StackTrace);
                      //throw;
                  }
              }
          }
  
          private void swap(char[] p1, char[] p2)
          {
              //throw new NotImplementedException();
              int l = p1.Length;
              for (int i = 0; i &lt; l; i++)
              {
                  char temp = p1[i];
                  p1[i] = p2[i];
                  p2[i] = temp;
              }
          }
  </code></pre>