title: C# Passing and returning a multidimensional array
body: <p>I have a 2D array, that I fill randomly with numbers. The code I have for this works fine, however, to organise my code better I'm wanting to put the "fill it randomly with numbers" part into a method. </p>
  
  <p>The array is created from the Main() method, as I plan on passing and returning the array to/from other methods that will manipulate it. I then tried to write the method for filling the array, but I'm unsure how to either pass a multidimensional array, or return one either. According to MSDN I need to use an "out" rather than a return.</p>
  
  <p>This is what I've tried so far:</p>
  
  <pre><code>    static void Main(string[] args)
      {
              int rows = 30;
              int columns = 80;
  
  
  
              int[,] ProcArea = new int[rows, columns];
  
              RandomFill(ProcArea[], rows, columns);
  
      }
  
      public static void RandomFill(out int[,] array, int rows, int columns)
      {
  
          array = new int[rows, columns];
  
  
          Random rand = new Random();
          //Fill randomly
          for (int r = 0; r &lt; rows; r++)
          {
              for (int c = 0; c &lt; columns; c++)
              {
                  if (rand.NextDouble() &lt; 0.55)
                  {
                  array[r, c] = 1;
              }
              else
              {
                  array[r, c] = 0;
              }
          }
      }
  </code></pre>
  
  <p>These are the errors I have:</p>
  
  <pre><code>"The best overloaded method match for 'ProcGen.Program.RandomFill(out int[*,*], int, int)' has some invalid arguments"
  "Argument 1: cannot convert from 'int' to 'out int[*,*]'"
  </code></pre>
  
  <p>What am I doing wrong, and what can I do to fix these errors? Also, am I right in thinking, because I'm using "out" that all I need to do is:</p>
  
  <pre><code>RandomFill(ProcArea[], rows, columns);
  </code></pre>
  
  <p>instead of?:</p>
  
  <pre><code>ProcArea = RandomFill(ProcArea[], rows, columns);
  </code></pre>
  
  <p>Is there a proper way of calling the method?</p>