GetMaxCharCount Method
Collapse the table of content
Expand the table of content

ASCIIEncoding.GetMaxCharCount Method

Calculates the maximum number of characters produced by decoding the specified number of bytes.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

public override int GetMaxCharCount (
	int byteCount
)
public int GetMaxCharCount (
	int byteCount
)
public override function GetMaxCharCount (
	byteCount : int
) : int

Parameters

byteCount

The number of bytes to decode.

Return Value

The maximum number of characters produced by decoding the specified number of bytes.

Exception typeCondition

ArgumentOutOfRangeException

byteCount is less than zero.

-or-

The resulting number of bytes is greater than the maximum number that can be returned as an int.

To calculate the exact array size required by GetChars to store the resulting characters, use GetCharCount. To calculate the maximum array size, use GetMaxCharCount. The GetCharCount method generally allows you to allocate less memory, whereas the GetMaxCharCount method generally executes faster.

The following example demonstrates how to use the GetMaxCharCount method to calculate the maximum number of characters needed to decode a specified number of bytes.

using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        ASCIIEncoding ascii = new ASCIIEncoding();
        int byteCount = 8;
        int maxCharCount = ascii.GetMaxCharCount(byteCount);
        Console.WriteLine(
            "Maximum of {0} characters needed to decode {1} bytes.",
            maxCharCount,
            byteCount
        );
    }
}

import System.*;
import System.Text.*;

class ASCIIEncodingExample
{
    public static void main(String[] args)
    {
        ASCIIEncoding ascii = new ASCIIEncoding();
        int byteCount = 8;
        int maxCharCount = ascii.GetMaxCharCount(byteCount);
        Console.WriteLine(
            "Maximum of {0} characters needed to decode {1} bytes.",
            String.valueOf(maxCharCount), String.valueOf(byteCount));
    } //main
} //ASCIIEncodingExample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft