c# int数组转byte数组

时间:2022-12-16 16:25:15

c# int[]转byte[] 

byte[]转int[]


数据互转

可以扩展成其他的数组转byte

           int[] intArray = new int[3];
intArray[0] = 511;
intArray[1] = 512;
intArray[2] = 513;

byte[] result = new byte[intArray.Length * sizeof(int)];
Buffer.BlockCopy(intArray, 0, result, 0, result.Length);
//下面的是反转
int[] ints = new int[result.Length / sizeof(int)];
Buffer.BlockCopy(result, 0, ints, 0, result.Length);

foreach(var item in ints)
{
Console.WriteLine(":::::" + item);
}