C# UnicodeEncoding GetBytes(Char[], Int32, Int32)
Description
UnicodeEncoding GetBytes(Char[], Int32, Int32)
When
overridden in a derived class, encodes a set of characters from the specified
character array into a sequence of bytes.
Syntax
UnicodeEncoding.GetBytes(Char[], Int32, Int32)
has the following syntax.
public virtual byte[] GetBytes(
char[] chars,/*ww w . j av a 2 s . co m*/
int index,
int count
)
Parameters
UnicodeEncoding.GetBytes(Char[], Int32, Int32)
has the following parameters.
chars
- The character array containing the set of characters to encode.index
- The index of the first character to encode.count
- The number of characters to encode.
Returns
UnicodeEncoding.GetBytes(Char[], Int32, Int32)
method returns
Example
using System;/* ww w. ja v a2s .c o m*/
using System.Text;
public class SamplesEncoding
{
public static void Main()
{
char[] chars = new char[] { 'z', 'a', '\u0306', '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
Encoding enc = Encoding.Unicode;
byte[] bytes = enc.GetBytes(chars, 1, 2);
for (int i = 0; i < bytes.Length; i++)
Console.Write("{0:X2} ", bytes[i]);
}
}
The code above generates the following result.