C# BitConverter ToChar
Description
BitConverter ToChar
returns a Unicode character converted
from two bytes at a specified position in a byte array.
Syntax
BitConverter.ToChar
has the following syntax.
public static char ToChar(
byte[] value,
int startIndex
)
Parameters
BitConverter.ToChar
has the following parameters.
value
- An array.startIndex
- The starting position within value.
Returns
BitConverter.ToChar
method returns A character formed by two bytes beginning at startIndex.
Example
The following code example converts elements of Byte arrays to Char values (Unicode characters) with the ToChar method.
using System;/* ww w .j a v a 2s. c o m*/
class BytesToCharDemo
{
public static void Main( )
{
byte[] bytes = {
32, 0, 0, 42, 0, 65, 0, 125, 0,
197, 0, 168, 3, 41, 4, 172, 32 };
char value = BitConverter.ToChar( bytes, 0 );
Console.WriteLine( value );
}
}
The code above generates the following result.