BitConverter.ToBoolean Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Przeciążenia
| ToBoolean(ReadOnlySpan<Byte>) |
Konwertuje zakres bajtów tylko do odczytu na wartość logiczną. |
| ToBoolean(Byte[], Int32) |
Zwraca wartość logiczną przekonwertowaną z bajtu na określonej pozycji w tablicy bajtów. |
ToBoolean(ReadOnlySpan<Byte>)
Konwertuje zakres bajtów tylko do odczytu na wartość logiczną.
public:
static bool ToBoolean(ReadOnlySpan<System::Byte> value);
public static bool ToBoolean (ReadOnlySpan<byte> value);
static member ToBoolean : ReadOnlySpan<byte> -> bool
Public Shared Function ToBoolean (value As ReadOnlySpan(Of Byte)) As Boolean
Parametry
- value
- ReadOnlySpan<Byte>
Zakres tylko do odczytu zawierający bajty do konwersji.
Zwraca
Wartość logiczna reprezentująca przekonwertowane bajty.
Wyjątki
Długość value jest mniejsza niż 1.
Dotyczy
ToBoolean(Byte[], Int32)
Zwraca wartość logiczną przekonwertowaną z bajtu na określonej pozycji w tablicy bajtów.
public:
static bool ToBoolean(cli::array <System::Byte> ^ value, int startIndex);
public static bool ToBoolean (byte[] value, int startIndex);
static member ToBoolean : byte[] * int -> bool
Public Shared Function ToBoolean (value As Byte(), startIndex As Integer) As Boolean
Parametry
- value
- Byte[]
Tablica bajtów.
- startIndex
- Int32
Indeks bajtu w celu value przekonwertowania.
Zwraca
true jeśli bajt w startIndex in value jest niezerowy; w przeciwnym razie , false.
Wyjątki
value to null.
startIndex jest mniejsza niż zero lub większa niż długość value minus 1.
Przykłady
Poniższy przykład kodu konwertuje elementy Byte tablic na Boolean wartości za pomocą ToBoolean metody .
// Example of the BitConverter::ToBoolean method.
using namespace System;
int main()
{
// Define an array of byte values.
array<Byte>^ bytes = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
Console::WriteLine("{0,5}{1,16}{2,10}\n", "index", "array element", "bool" );
// Convert each array element to a Boolean value.
for (int index = 0; index < bytes->Length; index++)
Console::WriteLine("{0,5}{1,16:X2}{2,10}", index, bytes[index],
BitConverter::ToBoolean(bytes, index));
}
// The example displays the following output:
// index array element bool
//
// 0 00 False
// 1 01 True
// 2 02 True
// 3 04 True
// 4 08 True
// 5 10 True
// 6 20 True
// 7 40 True
// 8 80 True
// 9 FF True
using System;
class Example
{
public static void Main( )
{
// Define an array of byte values.
byte[] bytes = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
Console.WriteLine("{0,5}{1,16}{2,10}\n", "index", "array element", "bool" );
// Convert each array element to a Boolean value.
for (int index = 0; index < bytes.Length; index++)
Console.WriteLine("{0,5}{1,16:X2}{2,10}", index, bytes[index],
BitConverter.ToBoolean(bytes, index));
}
}
// The example displays the following output:
// index array element bool
//
// 0 00 False
// 1 01 True
// 2 02 True
// 3 04 True
// 4 08 True
// 5 10 True
// 6 20 True
// 7 40 True
// 8 80 True
// 9 FF True
open System
// Define an array of byte values.
let bytes = [| 0uy; 1uy; 2uy; 4uy; 8uy; 16uy; 32uy; 64uy; 128uy; 255uy |]
printfn "%5s%16s%10s\n" "index" "array element" "bool"
// Convert each array element to a Boolean value.
for i = 0 to bytes.Length - 1 do
printfn $"{i,5}{bytes[i],16:X2}{BitConverter.ToBoolean(bytes, i), 10}"
// The example displays the following output:
// index array element bool
//
// 0 00 False
// 1 01 True
// 2 02 True
// 3 04 True
// 4 08 True
// 5 10 True
// 6 20 True
// 7 40 True
// 8 80 True
// 9 FF True
Module Example
Public Sub Main()
' Define an array of byte values.
Dim bytes() As Byte = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 }
Console.WriteLine("{0,5}{1,16}{2,10}\n", "index", "array element", "bool" )
' Convert each array element to a Boolean value.
For index As Integer = 0 To bytes.Length - 1
Console.WriteLine("{0,5}{1,16:X2}{2,10}", index, bytes(index),
BitConverter.ToBoolean(bytes, index))
Next
End Sub
End Module
' The example displays the following output:
' index array element bool
'
' 0 00 False
' 1 01 True
' 2 02 True
' 3 04 True
' 4 08 True
' 5 10 True
' 6 20 True
' 7 40 True
' 8 80 True
' 9 FF True
Uwagi
Aby przekonwertować wartość na reprezentację Boolean bajtów, wywołaj metodę GetBytes(Boolean) .