C#程序将一个字节范围从一个数组复制到另一个
使用Buffer.BlockCopy方法将字节范围从一个数组复制到另一个数组-
设置一个字节数组-
byte[] b1 = new byte[] {22, 49};
byte[] b2 = new byte[5];将字节从一个数组复制到另一个数组-
Buffer.BlockCopy(b1, 0, b2, 0, 2);
以下是完整的代码-
示例
using System;
class Demo {
static void Main(){
//字节数组
byte[] b1 = new byte[] {22, 49};
byte[] b2 = new byte[5];
//将字节从一个复制到另一个
Buffer.BlockCopy(b1, 0, b2, 0, 2);
/* calling the method with the byte array b2 that has the copied elements */
bufferFunc(b2);
}
static void bufferFunc(byte[] a) {
for (int j = 0; j < a.Length; j++) {
Console.Write(a[j]);
}
Console.WriteLine();
}
}输出结果
2249000
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短