C# Encoding GetBytes(Char[], Int32, Int32)

Description

Encoding 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

Encoding.GetBytes(Char[], Int32, Int32) has the following syntax.


public virtual byte[] GetBytes(
  char[] chars,/*w w  w .ja v  a2 s.  c o  m*/
  int index,
  int count
)

Parameters

Encoding.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

Encoding.GetBytes(Char[], Int32, Int32) method returns

Example


/*from  w w  w  .  ja  v a2s.  c om*/
using System;
using System.Text;

public class SamplesEncoding
{
    public static void Main()
    {
        char[] myChars = new char[] { 'z', 'a', '\u0306', '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
        Encoding enc = Encoding.UTF8;

        byte[] bytes = enc.GetBytes(myChars, 0, 3);

        for (int i = 0; i < bytes.Length; i++)
            Console.Write("{0:X2} ", bytes[i]);
        Console.WriteLine();
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding