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

Description

Encoding GetByteCount(Char[], Int32, Int32) When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array.

Syntax

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


public abstract int GetByteCount(
  char[] chars,/*  w  w w.j av  a2  s  . c om*/
  int index,
  int count
)

Parameters

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

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

Example


using System;/*from w  ww .j av  a 2  s. com*/
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;
        Console.Write("{0,-30} :", enc.ToString());
        int iBC = enc.GetByteCount(myChars, 0, 3);
        Console.Write(" {0,-3}", iBC);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding