C# ASCIIEncoding GetMaxByteCount

Description

ASCIIEncoding GetMaxByteCount Calculates the maximum number of bytes produced by encoding the specified number of characters.

Syntax

ASCIIEncoding.GetMaxByteCount has the following syntax.


public override int GetMaxByteCount(
  int charCount
)

Parameters

ASCIIEncoding.GetMaxByteCount has the following parameters.

  • charCount - The number of characters to encode.

Returns

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

Example


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

class ASCIIEncodingExample {
    public static void Main() {
        ASCIIEncoding ascii = new ASCIIEncoding();
        int charCount = 2;
        int maxByteCount = ascii.GetMaxByteCount(charCount);
        Console.WriteLine(
            "Maximum of {0} bytes needed to encode {1} characters.",
            maxByteCount,
            charCount
        );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding