C# UnicodeEncoding GetByteCount(Char[], Int32, Int32)

Description

UnicodeEncoding GetByteCount(Char[], Int32, Int32) Calculates the number of bytes produced by encoding a set of characters from the specified character array.

Syntax

UnicodeEncoding.GetByteCount(Char[], Int32, Int32) has the following syntax.


public override int GetByteCount(
  char[] chars,/*from   www  .  j av  a  2 s.  c om*/
  int index,
  int count
)

Parameters

UnicodeEncoding.GetByteCount(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.GetByteCount(Char[], Int32, Int32) method returns The number of bytes produced by encoding the specified characters.

Example

The following code example demonstrates how to use the GetByteCount method to return the number of bytes required to encode an array of Unicode characters using UnicodeEncoding.


using System;/*from   w  w w . j a  v  a 2 s.c om*/
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        Char[] chars = new Char[] {
            '\u0023', // #
            '\u0025', // %
            '\u03a0', // Pi
            '\u03a3'  // Sigma
        };

        UnicodeEncoding Unicode = new UnicodeEncoding();
        int byteCount = Unicode.GetByteCount(chars, 1, 2);
        Console.WriteLine(byteCount);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding