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