英語で読む

次の方法で共有


BitConverter.ToBoolean メソッド

定義

オーバーロード

ToBoolean(ReadOnlySpan<Byte>)

読み取り専用のバイト スパンをブール値に変換します。

ToBoolean(Byte[], Int32)

バイト配列内の指定位置にあるバイトから変換されたブール値を返します。

ToBoolean(ReadOnlySpan<Byte>)

読み取り専用のバイト スパンをブール値に変換します。

C#
public static bool ToBoolean (ReadOnlySpan<byte> value);

パラメーター

value
ReadOnlySpan<Byte>

変換するバイトを含む読み取り専用のスパン。

戻り値

Boolean

変換後のバイトを表すブール値。

例外

value 長さが 1 未満です。

適用対象

.NET 7 およびその他のバージョン
製品 バージョン
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Standard 2.1

ToBoolean(Byte[], Int32)

バイト配列内の指定位置にあるバイトから変換されたブール値を返します。

C#
public static bool ToBoolean (byte[] value, int startIndex);

パラメーター

value
Byte[]

バイト配列。

startIndex
Int32

変換するバイトの value インデックス。

戻り値

Boolean

startIndexvalue にあるバイトが 0 以外の場合は true。それ以外の場合は false

例外

valuenullです。

startIndex が 0 未満か、value の長さから 1 を引いた値より大きい値です。

次のコード例では、メソッドを使用して配列のByte要素を値にBooleanToBoolean変換します。

C#
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

注釈

値を Boolean バイト表現に変換するには、メソッドを GetBytes(Boolean) 呼び出します。

こちらもご覧ください

適用対象

.NET 7 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0