C# unsafe value type array to byte array conversions

后端 未结 7 821
梦毁少年i
梦毁少年i 2020-11-30 08:20

I use an extension method to convert float arrays into byte arrays:

public static unsafe byte[] ToByteArray(this float[] floatArray, int count)
{
    int arr         


        
7条回答
  •  广开言路
    2020-11-30 08:43

    This question is the reverse of What is the fastest way to convert a float[] to a byte[]?.

    I've answered with a union kind of hack to skip the whole copying of the data. You could easily reverse this (length = length *sizeof(Double).

提交回复
热议问题