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.