title: C# Multiply Each row of array by set of factors
body: <p>I have a multidimensional array and I want to multiply each row of it by a single dimensional array containing factors to create a new multidimensional array. However, the number of rows in the multidimensional array will vary from one run to the next, so I'll need a way to loop the multiplication through each row of the multidimensional array until the last row is reached. </p>
  
  <p>Here is a simple example, I have multidimensional array:
  { { 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12} }</p>
  
  <p>and I want to multiply each row by:
  {0.5, 0.4, 0, 0.8}</p>
  
  <p>to get:
  { { 1*0.5, 2*0.4, 3*0, 4*0.8}, { 5*0.5, 6*0.4, 7*0, 8*0.8}, { 9*0.5, 10*0.4, 11*0, 12*0.8} }</p>
  
  <p>I've tried to use .Length within a for loop using the example code.</p>
  
  <pre><code>double [] factors = {0.5, 0.4, 0, 0.8};
  
  int [,] myarray = new int [3,4] {
  { 1, 2, 3, 4},
  { 5, 6, 7, 8},
  { 9, 10, 11, 12}
  };
  
  double [] output = new double[myarray.Length];
  for(int i = 0; i &lt; myarray.Length; ++i)
      output[i] = myarray[i] * factors;
  </code></pre>
  
  <p>I'm getting syntax errors that extension method 'Length' cannot be applied to type int, and also indexing with [] cannot be applied to type int.</p>