ภาพรวม
ใช้ Buffer.ByteLength() ดึง ขนาดรวมของอาร์เรย์เป็นไบต์ (จำนวนองค์ประกอบ × ขนาดต่อองค์ประกอบ)
รูปแบบการใช้งาน
byte[] b = { 5, 9, 19, 23, 29, 35, 55, 78 };
int len = Buffer.ByteLength(b); // 8 (8 elements × 1 byte)
ตัวอย่างโค้ดเต็ม
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
ข้อมูลเพิ่มเติม
| ชนิด | ขนาด (ไบต์) | Buffer.ByteLength(array) |
|---|---|---|
byte[] | 1 | Length × 1 |
short[] / ushort[] | 2 | Length × 2 |
int[] / uint[] / float[] | 4 | Length × 4 |
long[] / ulong[] / double[] | 8 | Length × 8 |