BitConverter.ToBoolean 메서드

정의

오버로드

ToBoolean(ReadOnlySpan<Byte>)

읽기 전용 바이트 범위를 부울 값으로 변환합니다.

ToBoolean(Byte[], Int32)

바이트에서 변환된 부울 값을 바이트 배열의 지정된 위치에 반환합니다.

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

매개 변수

value
ReadOnlySpan<Byte>

변환할 바이트를 포함하는 읽기 전용 범위입니다.

반환

Boolean

변환된 바이트를 나타내는 부울입니다.

예외

길이 value 가 1보다 작습니다.

적용 대상

ToBoolean(Byte[], Int32)

바이트에서 변환된 부울 값을 바이트 배열의 지정된 위치에 반환합니다.

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

매개 변수

value
Byte[]

바이트 배열입니다.

startIndex
Int32

변환할 바이 value 트의 인덱스입니다.

반환

Boolean

startIndexvalue에 있는 바이트가 0이 아니면 true이고 그렇지 않으면 false입니다.

예외

value이(가) null인 경우

startIndex가 0보다 작거나 value - 1의 길이보다 큰 경우

예제

다음 코드 예제에서는 배열의 Byte 요소를 메서드를 사용하여 Boolean 값으로 ToBoolean 변환합니다.

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

설명

값을 바이트 표현으로 Boolean 변환하려면 메서드를 호출합니다 GetBytes(Boolean) .

추가 정보

적용 대상