title: C# Passing array by reference
body: <p>I know there are very similar questions but I need to know what's going on in this specific case. I wrote a function to reverse items of a multidimensional array along a specific dimension. To do this I convert the multidimensional array to a jagged array and than recursively find the array dimension where perform the reversal.
  </p>
  
  <pre><code>public static void Reverse(this Array array, int dimension, int start, int end)
  {
      object[] jag = array.ToJaggedArray();
  
      if (!jag.ReverseAux(0, dimension, start, end))
          throw new ArgumentOutOfRangeException("dimension", dimension, "Dimension must be nonnegative and less than array dimensions number.");
  
      array = jag;
  }
  </code></pre>
  
  <p>Now my problem is that when I run this method my input array has not been modified. Shouldn't an array be passed by reference? When I assign <code>array = jag</code> why it is correctly assigned inside the method but not outside?</p>
  
  <p>For example:
  </p>
  
  <pre><code>// create 2D array of strings
  string[,] ar = {{"00", "01", "02"},
                  {"10", "11", "12"},
                  {"20", "21", "22"}};
  // reverse the first dimension (rows)
  ar.Reverse(0, 0, 2);
  // show the result
  MessageBox.Show(ar.ToString(null, null));
  </code></pre>
  
  <p>The output is <code>{{00, 01, 02}, {10, 11, 12}, {20, 21, 22}}</code> that is exactly the original array. If I check the output in <code>Reverse</code> method
  </p>
  
  <pre><code>public static void Reverse(this Array array, int dimension, int start, int end)
  {
      //...
  
      array = jag;
      System.Windows.Forms.MessageBox.Show(array.ToString(null, null));
  }
  </code></pre>
  
  <p>this shows the correct reversed array <code>{{20, 21, 22}, {10, 11, 12}, {00, 01, 02}}</code>.</p>
  
  <p>Shouldn't an array be passed by reference? Why after the local assignment my input array is referencing the orignal pointer and not the assigned? Should I use <code>ref</code> keyword for array argument? If yes is it possible to continue using this method as an extension of <code>Array</code> type?</p>