C# 中的緩衝區塊複製


它從一個位元組陣列複製位元組到另一個位元組陣列。

例項

 現場演示

using System;
class Demo {
   static void Main() {
      // byte arrays
      byte[] b1 = new byte[] {55, 66, 77, 88, 99};
      byte[] b2 = new byte[8];
      // copying bytes from one to another
      Buffer.BlockCopy(b1, 0, b2, 0, 5);
      /* 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();
   }
}

輸出

5566778899000

更新於:2020-6-22

630 瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.