设置一个字节数组-
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