Export (0) Print
Expand All

BitConverter.GetBytes Method (Boolean)

Returns the specified Boolean value as an array of bytes.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static byte[] GetBytes(
	bool value
)

Parameters

value
Type: System.Boolean
A Boolean value.

Return Value

Type: System.Byte[]
An array of bytes with length 1.

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
*/


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft