This is called
serialization. You apparently need binary serialization into array of bytes used for many purposes. You need to use the class
System.BitConverter
,
http://msdn.microsoft.com/en-us/library/system.bitconverter.aspx[
^].
It allows you to convert to byte a single float element using
GetBytes(Single)
or
GetBytes(Double)
.
To do the whole thing, you need first serialize the length of the float array using
GetBytes(Int32)
, then serialize all float members in loop and concatenate all together (for example, use
Array.Copy
). Pre-create the resulting array at once with the length
sizeof(Int32) + ArrayLength*sizeof(Double)
(or
sizeof(Single)
).
You will probably need to right a matching
deserialization method — from array of byte to array of float (using
ToInt32
,
ToDouble
or
ToSingle
).
—SA