BitConverter.GetBytes Method (Boolean)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Returns the specified Boolean value as an array of bytes.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Boolean
A Boolean value.
The following code example converts the bit patterns of Boolean values to Byte arrays with the GetBytes method.
// Example of the BitConverter.GetBytes( bool ) method. using System; class Example { const string formatter = "{0,10}{1,16}"; // Convert a bool argument to a byte array and display it. public static void GetBytesBool(System.Windows.Controls.TextBlock outputBlock, bool argument) { byte[] byteArray = BitConverter.GetBytes(argument); outputBlock.Text += String.Format(formatter, argument, BitConverter.ToString(byteArray)) + "\n"; } public static void Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += String.Format( "This example of the BitConverter.GetBytes( bool ) " + "\nmethod generates the following output.\n") + "\n"; outputBlock.Text += String.Format(formatter, "bool", "byte array") + "\n"; outputBlock.Text += String.Format(formatter, "----", "----------") + "\n"; // Convert bool values and display the results. GetBytesBool(outputBlock, false); GetBytesBool(outputBlock, true); } } /* This example of the BitConverter.GetBytes( bool ) method generates the following output. bool byte array ---- ---------- False 00 True 01 */
Show: