BitConverter.ToBoolean 메서드

정의

오버로드

Name Description
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>

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

반품

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

예외

길이 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 의 인덱스입니다.

반품

true in startIndexvalue 의 바이트가 0이 아니면 0이 아니고, false그렇지 않으면 .

예외

valuenull입니다.

startIndex 가 0보다 작거나 길이 value 에서 1을 뺀 값보다 큽니다.

예제

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

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) .

추가 정보

적용 대상