How do I convert a double[] array to a byte[] array and vice versa?
class Program
{
static void Main(string[] args)
{
Console.WriteLine(sizeof(double));
Console.WriteLine(double.MaxValue);
double[] array = new double[] { 10.0, 20.0, 30.0, 40.0 };
byte[] convertedarray = ?
Console.Read();
}
}
Assuming you want the doubles placed in the corresponding byte array one after the other, LINQ can make short work out of this:
Alternatively, you could use
Buffer.BlockCopy():To convert back: