UTF7Encoding.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보다 작은 경우

또는 결과 문자 수가 정수로 반환될 수 있는 최대 수보다 큽니다.

대체가 발생했습니다(자세한 내용은 .NET의 문자 인코딩 참조). 및 DecoderFallbackDecoderExceptionFallback로 설정됩니다.

예제

다음 코드 예제에서는 메서드를 사용하여 GetMaxCharCount 지정된 바이트 수를 디코딩하여 생성된 최대 문자 수를 반환하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Text;
int main()
{
   UTF7Encoding^ utf7 = gcnew UTF7Encoding;
   int byteCount = 8;
   int maxCharCount = utf7->GetMaxCharCount( byteCount );
   Console::WriteLine( "Maximum of {0} characters needed to decode {1} bytes.", maxCharCount, byteCount );
}
using System;
using System.Text;

class UTF7EncodingExample {
    public static void Main() {
        UTF7Encoding utf7 = new UTF7Encoding();
        int byteCount = 8;
        int maxCharCount = utf7.GetMaxCharCount(byteCount);
        Console.WriteLine(
            "Maximum of {0} characters needed to decode {1} bytes.",
            maxCharCount,
            byteCount
        );
    }
}
Imports System.Text

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

설명

에 필요한 정확한 배열 크기를 계산 하려면 GetChars 애플리케이션에서는 결과 문자를 저장 하려면 GetCharCount합니다. 최대 배열 크기를 계산 하려면 애플리케이션을 사용할지 GetMaxCharCount합니다. 메서드는 일반적으로 더 GetCharCount 많은 메모리를 할당 하는 것을 허용 하지만 GetMaxCharCount 메서드는 일반적으로 더 빠르게 실행 됩니다.

GetMaxCharCount 는 현재 선택된 DecoderFallback최악의 경우를 포함하여 최악의 경우 숫자입니다. 잠재적으로 큰 문자열 GetMaxCharCount 을 사용하여 대체를 선택한 경우 큰 값을 반환할 수 있습니다.

대부분의 경우 이 메서드는 작은 문자열에 적합한 숫자를 반환합니다. 큰 문자열의 경우 매우 큰 버퍼를 사용하고 좀 더 적절한 버퍼를 초과하는 드문 경우에서 오류를 catch하는 중에서 선택해야 할 수 있습니다. 또는을 사용 하 여 다른 방법을 고려해 볼 수도 GetCharCount 있습니다 Decoder.Convert .

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

참고

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

적용 대상

추가 정보