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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短