BitConverter.ToBoolean() วิธีการใน C# ส่งกลับค่าบูลีนที่แปลงจากไบต์ที่ตำแหน่งที่ระบุในอาร์เรย์ไบต์
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
public static bool ToBoolean (byte[] arr, int startIndex);
ด้านบน arr คืออาร์เรย์ไบต์ ขณะที่ startIndex คือดัชนีของไบต์ภายในค่าหนึ่งๆ
ตัวอย่าง
ให้เราดูตัวอย่างการใช้วิธีการ BitConverter.ToBoolean() -
using System;
public class Demo {
public static void Main(){
byte[] arr = { 50, 100 };
Console.WriteLine("Array values...");
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine("{0} ", arr[i]);
}
Console.WriteLine("\nConverted values...");
for (int index = 0; index < arr.Length; index++) {
bool res = BitConverter.ToBoolean(arr, index);
Console.WriteLine(""+res);
}
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Array values... 50 100 Converted values... True True