BitConverter.ToBoolean-Methode
Gibt einen booleschen Wert zurück, der aus einem Byte an der angegebenen Position eines Bytearrays konvertiert wurde.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Shared Function ToBoolean ( _
value As Byte(), _
startIndex As Integer _
) As Boolean
'Usage
Dim value As Byte()
Dim startIndex As Integer
Dim returnValue As Boolean
returnValue = BitConverter.ToBoolean(value, startIndex)
public static bool ToBoolean (
byte[] value,
int startIndex
)
public:
static bool ToBoolean (
array<unsigned char>^ value,
int startIndex
)
public static boolean ToBoolean (
byte[] value,
int startIndex
)
public static function ToBoolean (
value : byte[],
startIndex : int
) : boolean
Parameter
- value
Ein Bytearray.
- startIndex
Die Anfangsposition in value.
Rückgabewert
true, wenn das Byte an der Position startIndex in value ungleich null ist, andernfalls false.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
value ist NULL (Nothing in Visual Basic). |
|
startIndex ist kleiner als 0 (null) oder größer als die Länge von value minus 1. |
Beispiel
Im folgenden Codebeispiel werden Elemente von Byte-Arrays mithilfe der ToBoolean-Methode in Boolean-Werte konvertiert.
' Example of the BitConverter.ToBoolean method.
Imports System
Imports Microsoft.VisualBasic
Module BytesToBoolDemo
Const formatter As String = "{0,5}{1,16}{2,10}"
' Convert a Byte array element to Boolean and display it.
Sub BAToBool( bytes( ) As Byte, index As Integer )
Dim value As Boolean = BitConverter.ToBoolean( bytes, index )
Console.WriteLine( formatter, index, _
BitConverter.ToString( bytes, index, 1 ), value )
End Sub
Sub Main( )
Dim byteArray as Byte( ) = _
{ 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 }
Console.WriteLine( _
"This example of the BitConverter.ToBoolean( Byte( ), " & _
"Integer ) " & vbCrLf & "method generates the " & _
"following output. It converts elements of " & vbCrLf & _
"a Byte array to Boolean values." & vbCrLf )
Console.WriteLine( "initial Byte array" )
Console.WriteLine( "------------------" )
Console.WriteLine( BitConverter.ToString( byteArray ) )
Console.WriteLine( )
Console.WriteLine( formatter, "index", "array element", "Boolean" )
Console.WriteLine( formatter, "-----", "-------------", "-------" )
' Convert Byte array elements to Boolean values.
BAToBool( byteArray, 0 )
BAToBool( byteArray, 1 )
BAToBool( byteArray, 3 )
BAToBool( byteArray, 5 )
BAToBool( byteArray, 8 )
BAToBool( byteArray, 9 )
End Sub
End Module
' This example of the BitConverter.ToBoolean( Byte( ), Integer )
' method generates the following output. It converts elements of
' a Byte array to Boolean values.
'
' initial Byte array
' ------------------
' 00-01-02-04-08-10-20-40-80-FF
'
' index array element Boolean
' ----- ------------- -------
' 0 00 False
' 1 01 True
' 3 04 True
' 5 10 True
' 8 80 True
' 9 FF True
// Example of the BitConverter.ToBoolean method.
using System;
class GetBytesBoolDemo
{
const string formatter = "{0,5}{1,16}{2,10}";
// Convert a byte array element to bool and display it.
public static void BAToBool( byte[ ] bytes, int index )
{
bool value = BitConverter.ToBoolean( bytes, index );
Console.WriteLine( formatter, index,
BitConverter.ToString( bytes, index, 1 ), value );
}
public static void Main( )
{
byte[ ] byteArray = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
Console.WriteLine(
"This example of the BitConverter.ToBoolean( byte[ ], " +
"int ) \nmethod generates the following output. It " +
"converts elements \nof a byte array to bool values.\n" );
Console.WriteLine( "initial byte array" );
Console.WriteLine( "------------------" );
Console.WriteLine( BitConverter.ToString( byteArray ) + '\n' );
Console.WriteLine( formatter, "index", "array element", "bool" );
Console.WriteLine( formatter, "-----", "-------------", "----" );
// Convert byte array elements to bool values.
BAToBool( byteArray, 0 );
BAToBool( byteArray, 1 );
BAToBool( byteArray, 3 );
BAToBool( byteArray, 5 );
BAToBool( byteArray, 8 );
BAToBool( byteArray, 9 );
}
}
/*
This example of the BitConverter.ToBoolean( byte[ ], int )
method generates the following output. It converts elements
of a byte array to bool values.
initial byte array
------------------
00-01-02-04-08-10-20-40-80-FF
index array element bool
----- ------------- ----
0 00 False
1 01 True
3 04 True
5 10 True
8 80 True
9 FF True
*/
// Example of the BitConverter::ToBoolean method.
using namespace System;
// Convert a byte array element to bool and display it.
void BAToBool( array<unsigned char>^bytes, int index )
{
bool value = BitConverter::ToBoolean( bytes, index );
Console::WriteLine( "{0,5}{1,16}{2,10}", index, BitConverter::ToString( bytes, index, 1 ), value );
}
int main()
{
array<unsigned char>^byteArray = {0,1,2,4,8,16,32,64,128,255};
Console::WriteLine( "This example of the BitConverter::ToBoolean( unsigned "
"char[ ], int ) \nmethod generates the following output. It "
"converts elements of a \nbyte array to bool values.\n" );
Console::WriteLine( "initial unsigned char array" );
Console::WriteLine( "---------------------------" );
Console::WriteLine( BitConverter::ToString( byteArray ) );
Console::WriteLine();
Console::WriteLine( "{0,5}{1,16}{2,10}", "index", "array element", "bool" );
Console::WriteLine( "{0,5}{1,16}{2,10}", "-----", "-------------", "----" );
// Convert byte array elements to bool values.
BAToBool( byteArray, 0 );
BAToBool( byteArray, 1 );
BAToBool( byteArray, 3 );
BAToBool( byteArray, 5 );
BAToBool( byteArray, 8 );
BAToBool( byteArray, 9 );
}
/*
This example of the BitConverter::ToBoolean( unsigned char[ ], int )
method generates the following output. It converts elements of a
byte array to bool values.
initial unsigned char array
---------------------------
00-01-02-04-08-10-20-40-80-FF
index array element bool
----- ------------- ----
0 00 False
1 01 True
3 04 True
5 10 True
8 80 True
9 FF True
*/
// Example of the BitConverter.ToBoolean method.
import System.*;
class GetBytesBoolDemo
{
private static String formatter = "{0,5}{1,16}{2,10}";
// Convert a byte array element to bool and display it.
public static void BAToBool(ubyte bytes[], int index)
{
boolean value = BitConverter.ToBoolean(bytes, index);
Console.WriteLine(formatter, (Int32)index,
BitConverter.ToString(bytes, index, 1), (System.Boolean)value);
} //BAToBool
public static void main(String[] args)
{
ubyte byteArray[] = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
Console.WriteLine(("This example of the "
+ "BitConverter.ToBoolean( byte[ ], int ) \n"
+ "method generates the following output."
+ " It converts elements \nof a byte array to bool values.\n"));
Console.WriteLine("initial byte array");
Console.WriteLine("------------------");
Console.WriteLine((BitConverter.ToString(byteArray) + '\n'));
Console.WriteLine(formatter, "index", "array element", "bool");
Console.WriteLine(formatter, "-----", "-------------", "----");
// Convert byte array elements to bool values.
BAToBool(byteArray, 0);
BAToBool(byteArray, 1);
BAToBool(byteArray, 3);
BAToBool(byteArray, 5);
BAToBool(byteArray, 8);
BAToBool(byteArray, 9);
} //main
} //GetBytesBoolDemo
/*
This example of the BitConverter.ToBoolean( byte[ ], int )
method generates the following output. It converts elements
of a byte array to bool values.
initial byte array
------------------
00-01-02-04-08-10-20-40-80-FF
index array element bool
----- ------------- ----
0 00 False
1 01 True
3 04 True
5 10 True
8 80 True
9 FF True
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0