BitConverter.ToBoolean メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
| 名前 | 説明 |
|---|---|
| ToBoolean(ReadOnlySpan<Byte>) |
読み取り専用バイト スパンをブール値に変換します。 |
| ToBoolean(Byte[], Int32) |
バイト配列内の指定した位置にあるバイトから変換されたブール値を返します。 |
ToBoolean(ReadOnlySpan<Byte>)
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
読み取り専用バイト スパンをブール値に変換します。
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)
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
- ソース:
- BitConverter.cs
バイト配列内の指定した位置にあるバイトから変換されたブール値を返します。
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
startIndexのvalueのバイトが 0 以外の場合はfalse。
例外
value は nullです。
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) メソッドを呼び出します。