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 红包祝福语简短10字
18 周六早晨祝福语简短