ASCIIEncoding.GetMaxCharCount(Int32) 메서드

정의

지정한 수의 바이트를 디코딩할 경우 생성되는 최대 문자 수를 계산합니다.

public:
 override int GetMaxCharCount(int byteCount);
public override int GetMaxCharCount (int byteCount);
override this.GetMaxCharCount : int -> int
Public Overrides Function GetMaxCharCount (byteCount As Integer) As Integer

매개 변수

byteCount
Int32

디코딩할 바이트 수입니다.

반환

Int32

지정한 수의 바이트를 디코딩할 경우 생성되는 최대 문자 수입니다.

예외

byteCount가 0보다 작은 경우

또는 결과 바이트 수가 정수로 반환될 수 있는 최대 수보다 큽니다.

예제

다음 예제에서는 메서드를 사용하여 GetMaxCharCount 지정된 바이트 수를 디코딩하는 데 필요한 최대 문자 수를 계산하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
int main()
{
   ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
   int byteCount = 8;
   int maxCharCount = ascii->GetMaxCharCount( byteCount );
   Console::WriteLine( "Maximum of {0} characters needed to decode {1} bytes.", maxCharCount, byteCount );
}
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
        );
    }
}
Imports System.Text

Class ASCIIEncodingExample
    Public Shared Sub Main()
        Dim ascii As New ASCIIEncoding()
        Dim byteCount As Integer = 8
        Dim maxCharCount As Integer = ascii.GetMaxCharCount(byteCount)
        Console.WriteLine( _
            "Maximum of {0} characters needed to decode {1} bytes.", _
            maxCharCount, _
            byteCount _
        )
    End Sub
End Class

설명

메서드는 GetCharCount 결과 문자를 저장하는 데 필요한 GetChars 정확한 배열 크기를 계산하는 반면 메서드는 GetMaxCharCount 최대 배열 크기를 계산합니다. 메서드는 GetCharCount 일반적으로 더 적은 메모리를 할당하지만 메서드는 GetMaxCharCount 일반적으로 더 빠르게 실행됩니다.

GetMaxCharCount현재 선택 된에 대 한 최악의 경우를 포함 하 여 최악의 숫자를 검색 DecoderFallback 합니다. 최대 대체 길이가 n 인 디코더 대체가 있으면 메서드는 n * byteCountGetMaxCharCount 반환합니다.

GetMaxCharCount에는 관계가 없습니다 GetBytes . 애플리케이션에 사용 하는 유사한 함수가 필요 하는 경우 GetBytes를 사용 해야 GetMaxByteCount합니다.

참고

GetMaxCharCount(N)이 반드시와 동일한 값은 아닙니다 N* GetMaxCharCount(1) .

적용 대상

추가 정보