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