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.
double[,] A = new double[nx,ny];
// put some data in the array
for (i = 0; i < nx ; i++)
{
for (j = 0; j < 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 < nx ; i++)
{
for (j = 0; j < ny ; j++)
{
bw.Write(A[i,j]);
}
}
bw.Close();
fs.Close();
This code works, but I need better way and faster method. Any idea?