BitConverter.ToBoolean BitConverter.ToBoolean BitConverter.ToBoolean BitConverter.ToBoolean Method

Definizione

Overload

ToBoolean(ReadOnlySpan<Byte>) ToBoolean(ReadOnlySpan<Byte>) ToBoolean(ReadOnlySpan<Byte>) ToBoolean(ReadOnlySpan<Byte>)
ToBoolean(Byte[], Int32) ToBoolean(Byte[], Int32) ToBoolean(Byte[], Int32) ToBoolean(Byte[], Int32)

Restituisce un valore booleano convertito da un byte in una posizione specificata in una matrice di byte.Returns a Boolean value converted from the byte at a specified position in a byte array.

ToBoolean(ReadOnlySpan<Byte>) ToBoolean(ReadOnlySpan<Byte>) ToBoolean(ReadOnlySpan<Byte>) ToBoolean(ReadOnlySpan<Byte>)

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

Parametri

Restituisce

ToBoolean(Byte[], Int32) ToBoolean(Byte[], Int32) ToBoolean(Byte[], Int32) ToBoolean(Byte[], Int32)

Restituisce un valore booleano convertito da un byte in una posizione specificata in una matrice di byte.Returns a Boolean value converted from the byte at a specified position in a byte array.

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

Parametri

value
Byte[]

Matrice di byte.A byte array.

startIndex
Int32 Int32 Int32 Int32

Indice del byte all'interno di value.The index of the byte within value.

Restituisce

true se il byte in startIndex di value è diverso da zero; in caso contrario false.true if the byte at startIndex in value is nonzero; otherwise, false.

Eccezioni

startIndexè minore di zero o maggiore della lunghezza di value meno 1.startIndex is less than zero or greater than the length of value minus 1.

Esempi

Nell'esempio di codice seguente gli elementi Byte delle matrici vengono Boolean convertiti in ToBoolean valori con il metodo.The following code example converts elements of Byte arrays to Boolean values with the ToBoolean method.

// 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
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

Commenti

Per convertire un Boolean valore nella relativa rappresentazione in byte, chiamare GetBytes(Boolean) il metodo.To convert a Boolean value to its byte representation, call the GetBytes(Boolean) method.

Vedi anche

Si applica a