title: Is there a better way to write a 2-dimensional array into a binary file?
body: <p>I have a 2D array and would like to store in a binary file. To my knowledge, I wrote the following code to transfer the data into a binary file.</p>
  
  <pre><code>double[,] A = new double[nx,ny];
  // put some data in the array
  for (i = 0; i &lt; nx ; i++)
  {
      for (j = 0; j &lt; ny ; j++)
      {
          A[i,j] = ...;
      }
  }
  string path = "address";
  FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
  BinaryWriter bw = new BinaryWriter(fs);
  for (i = 0; i &lt; nx ; i++)
  {
      for (j = 0; j &lt; ny ; j++)
      {
          bw.Write(A[i,j]);
      }
  }
  bw.Close();
  fs.Close();
  </code></pre>
  
  <p>This code works, but I need better way and faster method.
  Any idea?</p>