UTF7Encoding.GetByteCount 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
计算对一组字符进行编码时产生的字节数。
重载
| GetByteCount(String) | 计算对指定 String 对象中的字符进行编码时产生的字节数。 | 
| GetByteCount(Char*, Int32) | 计算对从指定的字符指针开始的一组字符进行编码时产生的字节数。 | 
| GetByteCount(Char[], Int32, Int32) | 计算对指定字符数组中的一组字符进行编码时产生的字节数。 | 
GetByteCount(String)
- Source:
- UTF7Encoding.cs
- Source:
- UTF7Encoding.cs
- Source:
- UTF7Encoding.cs
计算对指定 String 对象中的字符进行编码时产生的字节数。
public:
 override int GetByteCount(System::String ^ s);public override int GetByteCount (string s);[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount (string s);override this.GetByteCount : string -> int[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : string -> intPublic Overrides Function GetByteCount (s As String) As Integer参数
返回
对指定字符进行编码后生成的字节数。
- 属性
例外
              s 为 null (Nothing)。
得到的字节数大于可作为 int 返回的最大数量。
(发生回退,有关详细信息,请参阅 .NET) 中的字符编码 。
-和-
示例
下面的代码示例演示如何使用 GetByteCount 方法返回对字符数组进行编码所需的字节数。
using namespace System;
using namespace System::Text;
int main()
{
   
   // Unicode characters.
   
   // Pi
   // Sigma
   array<Char>^chars = {L'\u03a0',L'\u03a3',L'\u03a6',L'\u03a9'};
   UTF7Encoding^ utf7 = gcnew UTF7Encoding;
   int byteCount = utf7->GetByteCount( chars, 1, 2 );
   Console::WriteLine( "{0} bytes needed to encode characters.", byteCount );
}
using System;
using System.Text;
class UTF7EncodingExample {
    public static void Main() {
        // Unicode characters.
        Char[] chars = new Char[] {
            '\u0023', // #
            '\u0025', // %
            '\u03a0', // Pi
            '\u03a3'  // Sigma
        };
        UTF7Encoding utf7 = new UTF7Encoding();
        int byteCount = utf7.GetByteCount(chars, 1, 2);
        Console.WriteLine(
            "{0} bytes needed to encode characters.", byteCount
        );
    }
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class UTF7EncodingExample
    
    Public Shared Sub Main()
        ' Unicode characters.
        ' ChrW(35)  = #
        ' ChrW(37)  = %
        ' ChrW(928) = Pi
        ' ChrW(931) = Sigma
        Dim chars() As Char = {ChrW(35), ChrW(37), ChrW(928), ChrW(931)}
        
        Dim utf7 As New UTF7Encoding()
        Dim byteCount As Integer = utf7.GetByteCount(chars, 1, 2)
        Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
    End Sub
End Class
注解
为了计算存储生成的字节所需的确切数组大小 GetBytes ,应用程序使用 GetByteCount。 若要计算最大数组大小,应用程序应使用 GetMaxByteCount。 GetByteCount方法通常允许分配较少的内存,而 GetMaxByteCount 方法的执行速度通常更快。
另请参阅
适用于
GetByteCount(Char*, Int32)
- Source:
- UTF7Encoding.cs
- Source:
- UTF7Encoding.cs
- Source:
- UTF7Encoding.cs
重要
此 API 不符合 CLS。
计算对从指定的字符指针开始的一组字符进行编码时产生的字节数。
public:
 override int GetByteCount(char* chars, int count);[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public override int GetByteCount (char* chars, int count);[System.CLSCompliant(false)]
public override int GetByteCount (char* chars, int count);[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount (char* chars, int count);[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount (char* chars, int count);[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
override this.GetByteCount : nativeptr<char> * int -> int[<System.CLSCompliant(false)>]
override this.GetByteCount : nativeptr<char> * int -> int[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : nativeptr<char> * int -> int[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : nativeptr<char> * int -> int参数
- chars
- Char*
指向第一个要编码的字符的指针。
- count
- Int32
要编码的字符的数目。
返回
对指定字符进行编码后生成的字节数。
- 属性
例外
              chars 为 null(在 Visual Basic .NET 中为 Nothing)。
发生回退(有关详细信息,请参阅采用 .NET 的字符编码)
-和-
注解
为了计算存储生成的字节所需的确切数组大小 GetBytes ,应用程序使用 GetByteCount。 若要计算最大数组大小,应用程序应使用 GetMaxByteCount。 GetByteCount方法通常允许分配较少的内存,而 GetMaxByteCount 方法的执行速度通常更快。
另请参阅
适用于
GetByteCount(Char[], Int32, Int32)
- Source:
- UTF7Encoding.cs
- Source:
- UTF7Encoding.cs
- Source:
- UTF7Encoding.cs
计算对指定字符数组中的一组字符进行编码时产生的字节数。
public:
 override int GetByteCount(cli::array <char> ^ chars, int index, int count);public override int GetByteCount (char[] chars, int index, int count);override this.GetByteCount : char[] * int * int -> intPublic Overrides Function GetByteCount (chars As Char(), index As Integer, count As Integer) As Integer参数
- chars
- Char[]
包含要编码的字符集的字符数组。
- index
- Int32
第一个要编码的字符的索引。
- count
- Int32
要编码的字符的数目。
返回
对指定字符进行编码后生成的字节数。
例外
              chars 为 null (Nothing)。
              index 或 count 小于零。
或
              index 和 count 不表示 chars中的有效范围。
- 或 -
得到的字节数大于可作为 int 返回的最大数量。
发生回退(有关详细信息,请参阅采用 .NET 的字符编码)
-和-
示例
下面的代码示例演示如何使用 GetByteCount 方法返回对 Unicode 字符数组进行编码所需的字节数。
using namespace System;
using namespace System::Text;
int main()
{
   
   // Unicode characters.
   
   // Pi
   // Sigma
   array<Char>^chars = {L'\u03a0',L'\u03a3',L'\u03a6',L'\u03a9'};
   UTF7Encoding^ utf7 = gcnew UTF7Encoding;
   int byteCount = utf7->GetByteCount( chars, 1, 2 );
   Console::WriteLine( "{0} bytes needed to encode characters.", byteCount );
}
using System;
using System.Text;
class UTF7EncodingExample {
    public static void Main() {
        // Unicode characters.
        Char[] chars = new Char[] {
            '\u0023', // #
            '\u0025', // %
            '\u03a0', // Pi
            '\u03a3'  // Sigma
        };
        UTF7Encoding utf7 = new UTF7Encoding();
        int byteCount = utf7.GetByteCount(chars, 1, 2);
        Console.WriteLine(
            "{0} bytes needed to encode characters.", byteCount
        );
    }
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class UTF7EncodingExample
    
    Public Shared Sub Main()
        ' Unicode characters.
        ' ChrW(35)  = #
        ' ChrW(37)  = %
        ' ChrW(928) = Pi
        ' ChrW(931) = Sigma
        Dim chars() As Char = {ChrW(35), ChrW(37), ChrW(928), ChrW(931)}
        
        Dim utf7 As New UTF7Encoding()
        Dim byteCount As Integer = utf7.GetByteCount(chars, 1, 2)
        Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
    End Sub
End Class
注解
为了计算存储生成的字节所需的 GetBytes 确切数组大小,应用程序使用 GetByteCount。 若要计算最大数组大小,应用程序应使用 GetMaxByteCount。 GetByteCount方法通常允许分配较少的内存,而 GetMaxByteCount 方法的执行速度通常更快。