ASCIIEncoding.GetMaxByteCount(Int32) 메서드

정의

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

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

매개 변수

charCount
Int32

인코딩할 문자 수입니다.

반환

Int32

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

예외

charCount가 0보다 작은 경우

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

예제

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

using namespace System;
using namespace System::Text;
int main()
{
   ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
   int charCount = 2;
   int maxByteCount = ascii->GetMaxByteCount( charCount );
   Console::WriteLine( "Maximum of {0} bytes needed to encode {1} characters.", maxByteCount, charCount );
}
using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        ASCIIEncoding ascii = new ASCIIEncoding();
        int charCount = 2;
        int maxByteCount = ascii.GetMaxByteCount(charCount);
        Console.WriteLine(
            "Maximum of {0} bytes needed to encode {1} characters.",
            maxByteCount,
            charCount
        );
    }
}
Imports System.Text

Class ASCIIEncodingExample
    Public Shared Sub Main()
        Dim ascii As New ASCIIEncoding()
        Dim charCount As Integer = 2
        Dim maxByteCount As Integer = ascii.GetMaxByteCount(charCount)
        Console.WriteLine( _
            "Maximum of {0} bytes needed to encode {1} characters.", _
            maxByteCount, _
            charCount _
        )
    End Sub
End Class

설명

메서드는 GetByteCount 결과 바이트를 저장하는 데 필요한 GetBytes 정확한 배열 크기를 계산하는 반면 메서드는 GetMaxByteCount 최대 배열 크기를 계산합니다. 이 메서드는 GetByteCount 일반적으로 메모리를 적게 할당하지만 메서드는 GetMaxByteCount 일반적으로 더 빠르게 실행됩니다.

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

이 메서드는 GetMaxByteCount 이전 인코딩 작업의 잠재적인 남은 서로게이트를 고려합니다. 따라서 개체가 ASCIIEncoding 기본 대체 대체를 사용하거나 사용자 지정 대체 대체가 가능한 단일 대체 문자로 정의된 경우 메서드는 + 1을 반환합니다 charCount . 개체가 ASCIIEncoding 둘 이상의 대체 문자를 사용하여 대체 대체를 사용하는 경우 메서드는 n * (charCount + 1)을 반환합니다. 여기서 n 은 대체 문자의 최대 수입니다.

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

참고

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

적용 대상

추가 정보