C# 中的緩衝區型別
若要處理位元組範圍,請在 C# 中使用緩衝區型別。它的方法 Buffer.BlockCopy 可將位元組從一個位元組陣列複製到另一個位元組陣列。
示例
using System; class Demo { static void Main() { // byte arrays byte[] b1 = new byte[] {39, 45, 58 }; byte[] b2 = new byte[5]; // copying bytes from one to another Buffer.BlockCopy(b1, 0, b2, 0, 3); /* 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(); } }
輸出
39455800
廣告