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

Description

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

Syntax

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


public override int GetByteCount(
  char[] chars,// ww  w .  ja  v a 2 s . c  om
  int index,
  int count
)

Parameters

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

ASCIIEncoding.GetByteCount(Char[], Int32, Int32) method returns The number of bytes produced by encoding the specified characters.

Example


using System;//w  w w  . j a va  2 s .c o m
using System.Text;

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

        ASCIIEncoding ascii = new ASCIIEncoding();
        int byteCount = ascii.GetByteCount(chars, 1, 2);
        Console.WriteLine(
            "{0} bytes needed to encode characters.", byteCount
        );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding