อ่านแต่ละไบต์โดยใช้วิธี GetByte() ใน C# -
ตั้งค่าอาร์เรย์ -
int[] arr = { 3, 4, 12 }; ตอนนี้ ใช้ Buffer.GetByte() เพื่อแสดงองค์ประกอบอาร์เรย์และอ่านแต่ละไบต์ -
for (int i = 0; i < Buffer.ByteLength(arr); i++) {
Console.WriteLine(Buffer.GetByte(arr, i));
} ต่อไปนี้เป็นรหัส −
ตัวอย่าง
using System;
using System.Text;
public class Demo {
public static void Main() {
int[] arr = { 3, 4, 12 };
// loop through the byte array
for (int i = 0; i < Buffer.ByteLength(arr); i++) {
Console.WriteLine(Buffer.GetByte(arr, i));
}
}
} ผลลัพธ์
3 0 0 0 4 0 0 0 12 0 0 0