UnicodeEncoding.GetMaxCharCount(Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정한 수의 바이트를 디코딩할 경우 생성되는 최대 문자 수를 계산합니다.
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
디코딩할 바이트 수입니다.
반환
지정한 수의 바이트를 디코딩할 경우 생성되는 최대 문자 수입니다.
예외
대체가 발생했습니다(자세한 내용은 .NET의 문자 인코딩 참조). 및 DecoderFallback이 DecoderExceptionFallback로 설정됩니다.
예제
다음 예제에서는 메서드를 사용하여 GetMaxCharCount 지정된 바이트 수를 디코딩하여 생성된 최대 문자 수를 반환하는 방법을 보여 줍니다.
using namespace System;
using namespace System::Text;
int main()
{
UnicodeEncoding^ Unicode = gcnew UnicodeEncoding;
int byteCount = 8;
int maxCharCount = Unicode->GetMaxCharCount( byteCount );
Console::WriteLine( "Maximum of {0} characters needed to decode {1} bytes.", maxCharCount, byteCount );
}
using System;
using System.Text;
class UnicodeEncodingExample {
public static void Main() {
UnicodeEncoding Unicode = new UnicodeEncoding();
int byteCount = 8;
int maxCharCount = Unicode.GetMaxCharCount(byteCount);
Console.WriteLine(
"Maximum of {0} characters needed to decode {1} bytes.",
maxCharCount,
byteCount
);
}
}
Imports System.Text
Class UnicodeEncodingExample
Public Shared Sub Main()
Dim uni As New UnicodeEncoding()
Dim byteCount As Integer = 8
Dim maxCharCount As Integer = uni.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 합니다. 잠재적으로 크기가 매우 긴 문자열을 사용 하 여 대체 (fallback)를 선택 하면에서 GetMaxCharCount 많은 값을 검색 합니다.
대부분의 경우이 메서드는 작은 문자열의 적절 한 숫자를 검색 합니다. 큰 문자열의 경우 매우 큰 버퍼를 사용하고 좀 더 적절한 버퍼를 초과하는 드문 경우에서 오류를 catch하는 중에서 선택해야 할 수 있습니다. 또는을 사용 하 여 다른 방법을 고려해 볼 수도 GetCharCount 있습니다 Convert .
GetMaxCharCount에는 관계가 없습니다 GetBytes . 애플리케이션에 사용 하는 유사한 함수가 필요 하는 경우 GetBytes를 사용 해야 GetMaxByteCount합니다.
참고
GetMaxCharCount(N)
이 반드시와 동일한 값은 아닙니다 N* GetMaxCharCount(1)
.