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]
}

 

1 byte[] src ={1,2,3,4,5};
2 byte[] dest = new byte[src.Length];
3 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  方法

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM