C# 常见的字节数组 byte[] 复制方法

byte[] src ={1,2,3,4,5};
byte[] dest = new byte[src.Length];
for(int i=0; i<src.Length; i++)
{
    dest[i] = src[i]
}
byte[] src ={1,2,3,4,5};
byte[] dest = new byte[src.Length];
Array.Copy(src, dest, src.Length);
byte[] src ={1,2,3,4,5};
byte[] dest;
dest =(byte[])src.Clone();

2015年7月2日  craigtao  新增 Buffer.BlockCopy  方法

byte[] srcArray = new byte[] { 0x01, 0x02, 0x03, 0x04 };
byte[] dstArray = new byte[srcArray.Length];
 
Buffer.BlockCopy(srcArray, 0, dstArray, 0, srcArray.Length);

猜你喜欢

转载自blog.csdn.net/u014453443/article/details/85161387