ASCIIEncoding.GetMaxCharCount(Int32) 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
计算对指定数目的字节进行解码时产生的最大字符数。
public:
 override int GetMaxCharCount(int byteCount);public override int GetMaxCharCount (int byteCount);override this.GetMaxCharCount : int -> intPublic Overrides Function GetMaxCharCount (byteCount As Integer) As Integer参数
- byteCount
- Int32
要解码的字节数。
返回
对指定数目的字节进行解码时所产生的最大字符数。
例外
示例
下面的示例演示如何使用 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 的解码器回退,该方法 GetMaxCharCount 将返回 n * byteCount。
GetMaxCharCount与之间没有关系 GetBytes 。 如果应用程序需要使用类似的函数, GetBytes则应使用 GetMaxByteCount它。
备注
GetMaxCharCount(N)不一定与相同 N* GetMaxCharCount(1) 。