C# 程序计算数组中的字节数

csharpprogrammingserver side programming更新于 2025/9/17 8:40:00

设置字节数组 −

byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 };

计算字节数 −

Buffer.ByteLength(b)

以下是代码 −

示例

using System;
class Program {
   static void Main() {
      byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 };
      int len = Buffer.ByteLength(b);
      for (int i = 0; i < len; i++) {
         Console.WriteLine(b[i]);
      }
      Console.WriteLine("Length of byte array = "+len);
   }
}

输出

5
9
19
23
29
35
55
78
Length of byte array = 8

相关文章