2 차원 배열의 UInt16 값을 원시 바이트로 변환했습니다. 그 바이트를 가져 와서 원래의 2D 배열로 다시 변환하고 싶습니다만, 바이트 만 가질 때 이것을 수행하는 방법이 확실하지 않습니다. 즉, 원래 배열의 크기를 결정할 수있는 방법이 있습니다. 배열을 바이트로 변환 했습니까?byte []를 원래의 2d 배열로 변환
여기 내 코드입니다 :이 코드는 1 차원 배열에 바이트를 넣어 것입니다
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]);
}
,하지만 난 원래 2 차원 배열에 넣어 싶습니다. 이 모든 것이 원시 바이트 인 경우 가능합니까? 결국 REST 호출을 통해이 바이트를 보낼 것이며 수신 측은 원래 2D 배열로 다시 변환 할 바이트 만 갖게됩니다.