我已經採用了二維數組的UInt16值,並將其轉換爲原始字節。我想採取這些字節,並將它們轉換回原始的二維數組,但我不確定如何做到這一點,當我只有字節,即,有沒有辦法確定一個原始數組的尺寸,當所有你有沒有將數組轉換爲字節?將字節[]轉換爲原始二維數組
這裏是我的代碼:
UInt16[,] dataArray = new UInt16[,] {
{4, 6, 2},
{0, 2, 0},
{1, 3, 4}
};
long byteCountUInt16Array = dataArray.GetLength(0) * dataArray.GetLength(1) * sizeof(UInt16);
var bufferUInt16 = new byte[byteCountUInt16Array];
Buffer.BlockCopy(dataArray, 0, bufferUInt16, 0, bufferUInt16.Length);
//Here is where I try to convert the values and print them out to see if the values are still the same:
UInt16[] originalUInt16Values = new UInt16[bufferUInt16.Length/2];
Buffer.BlockCopy(bufferUInt16, 0, originalUInt16Values, 0, BufferUInt16.Length);
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Values---: " + originalUInt16Values[i]);
}
這個代碼將會把字節轉換成一維數組,但我想將它們放到原來的二維數組。如果我擁有的是原始字節,這可能嗎?我最終將通過REST調用發送這些字節,並且接收端只會將字節轉換回原始的二維數組。