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 arrays
byte[] b1 = new byte[] {22, 49};
byte[] b2 = new byte[5];
// copying bytes from one to another
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP