C# UnicodeEncoding GetMaxByteCount

Description

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

Syntax

UnicodeEncoding.GetMaxByteCount has the following syntax.


public override int GetMaxByteCount(
  int charCount
)

Parameters

UnicodeEncoding.GetMaxByteCount has the following parameters.

  • charCount - The number of characters to encode.

Returns

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

Example


//  www  . j  a va 2  s  .com
using System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        UnicodeEncoding Unicode = new UnicodeEncoding();
        int charCount = 2;
        int maxByteCount = Unicode.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