Does anyone know of an efficient way to flatten a 2d array (non-jagged) in C# to a 1d and back again. I know in the back end C# must hold onto it as a 1d array I would just
You can't get a managed byte[]
array from a byte[,]
without copying it out (not that I know of, anyway).
If you're comfortable with unsafe
code you can fix a byte*
on the array and I believe that should work:
fixed (byte* ptr = array)
{
for (int i = 0; i < N; ++i)
{
byte b = ptr[i];
// Do whatever you need.
}
}