C# UTF8Encoding GetMaxByteCount

Description

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

Syntax

UTF8Encoding.GetMaxByteCount has the following syntax.


public override int GetMaxByteCount(
  int charCount
)

Parameters

UTF8Encoding.GetMaxByteCount has the following parameters.

  • charCount - The number of characters to encode.

Returns

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

Example

The following example demonstrates how to use the GetMaxByteCount method to return the maximum number of bytes required to encode a specified number of characters.


//from  w ww  .  j a v  a2  s .c  om
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        UTF8Encoding utf8 = new UTF8Encoding();
        int charCount = 2;
        int maxByteCount = utf8.GetMaxByteCount(charCount);
        Console.WriteLine(maxByteCount);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding