C# Encoding GetMaxByteCount

Description

Encoding GetMaxByteCount When overridden in a derived class, calculates the maximum number of bytes produced by encoding the specified number of characters.

Syntax

Encoding.GetMaxByteCount has the following syntax.


public abstract int GetMaxByteCount(
  int charCount
)

Parameters

Encoding.GetMaxByteCount has the following parameters.

  • charCount - The number of characters to encode.

Returns

Encoding.GetMaxByteCount method returns The maximum number of bytes produced by encoding the specified number of characters.

Example


//from  w  w w.ja  va 2  s  .  c om
using System;
using System.Text;

public class SamplesEncoding
{

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

        int iBC = enc.GetByteCount(chars);
        Console.Write(" {0,-3}", iBC);

        int iMBC = enc.GetMaxByteCount(chars.Length);
        Console.Write(" {0,-3} :", iMBC);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding