BitConverter.GetBytes Method (Char)
Returns the specified Unicode character value as an array of bytes.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Char
A character to convert.
The order of bytes in the array returned by the GetBytes method depends on whether the computer architecture is little-endian or big-endian.
The following code example converts the bit patterns of Char values (Unicode characters) to Byte arrays with the GetBytes method.
// Example of the BitConverter.GetBytes( char ) method. using System; class GetBytesCharDemo { const string formatter = "{0,10}{1,16}"; // Convert a char argument to a byte array and display it. public static void GetBytesChar( char argument ) { byte[ ] byteArray = BitConverter.GetBytes( argument ); Console.WriteLine( formatter, argument, BitConverter.ToString( byteArray ) ); } public static void Main( ) { Console.WriteLine( "This example of the BitConverter.GetBytes( char ) " + "\nmethod generates the following output.\r\n" ); Console.WriteLine( formatter, "char", "byte array" ); Console.WriteLine( formatter, "----", "----------" ); // Convert char values and display the results. GetBytesChar( '\0' ); GetBytesChar( ' ' ); GetBytesChar( '*' ); GetBytesChar( '3' ); GetBytesChar( 'A' ); GetBytesChar( '[' ); GetBytesChar( 'a' ); GetBytesChar( '{' ); } } /* This example of the BitConverter.GetBytes( char ) method generates the following output. char byte array ---- ---------- 00-00 20-00 * 2A-00 3 33-00 A 41-00 [ 5B-00 a 61-00 { 7B-00 */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.