UTF7Encoding.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
要解码的字节数。
返回
对指定数目的字节进行解码时所产生的最大字符数。
例外
发生回退(有关详细信息,请参阅采用 .NET 的字符编码)
-和-
示例
下面的代码示例演示如何使用 GetMaxCharCount 方法返回通过解码指定字节数生成的最大字符数。
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 则可以返回较大的值。
在大多数情况下,此方法返回小字符串的合理数字。 对于大型字符串,可能需要选择使用非常大的缓冲区和捕获错误(在极少数情况下超出更合理的缓冲区)。 你可能还需要考虑使用或的其他方法 GetCharCountDecoder.Convert 。
GetMaxCharCount与之间没有关系 GetBytes 。 如果应用程序需要类似的函数才能与 一起使用 GetBytes,则应使用 GetMaxByteCount。
注意
              GetMaxCharCount(N)不一定与相同 N* GetMaxCharCount(1) 。