Decoder.GetCharCount 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在派生类中重写时,计算通过解码字节序列生成的字符数。
重载
| 名称 | 说明 |
|---|---|
| GetCharCount(ReadOnlySpan<Byte>, Boolean) |
在派生类中重写时,计算通过解码跨度中字节序列生成的字符数。 参数指示是否在计算后清除解码器的内部状态。 |
| GetCharCount(Byte*, Int32, Boolean) |
在派生类中重写时,计算解码从指定字节指针开始的字节序列生成的字符数。 参数指示是否在计算后清除解码器的内部状态。 |
| GetCharCount(Byte[], Int32, Int32) |
在派生类中重写时,计算通过解码指定字节数组中的字节序列生成的字符数。 |
| GetCharCount(Byte[], Int32, Int32, Boolean) |
在派生类中重写时,计算通过解码指定字节数组中的字节序列生成的字符数。 参数指示是否在计算后清除解码器的内部状态。 |
GetCharCount(ReadOnlySpan<Byte>, Boolean)
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
在派生类中重写时,计算通过解码跨度中字节序列生成的字符数。 参数指示是否在计算后清除解码器的内部状态。
public:
virtual int GetCharCount(ReadOnlySpan<System::Byte> bytes, bool flush);
public virtual int GetCharCount(ReadOnlySpan<byte> bytes, bool flush);
abstract member GetCharCount : ReadOnlySpan<byte> * bool -> int
override this.GetCharCount : ReadOnlySpan<byte> * bool -> int
Public Overridable Function GetCharCount (bytes As ReadOnlySpan(Of Byte), flush As Boolean) As Integer
参数
- bytes
- ReadOnlySpan<Byte>
要解码的字节范围。
- flush
- Boolean
true 模拟在计算后清除编码器的内部状态;否则,为 false.
返回
通过解码指定字节序列和内部缓冲区中的任何字节生成的字符数。
注解
此方法不会影响解码器的状态。
若要计算存储生成的字符所需的确切缓冲区大小 GetChars ,应用程序应使用 GetCharCount。
如果使用GetCharCount立即调用GetChars数据块,以便计算中包括上一个块中的任何尾随字节。
适用于
GetCharCount(Byte*, Int32, Boolean)
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
重要
此 API 不符合 CLS。
在派生类中重写时,计算解码从指定字节指针开始的字节序列生成的字符数。 参数指示是否在计算后清除解码器的内部状态。
public:
virtual int GetCharCount(System::Byte* bytes, int count, bool flush);
[System.CLSCompliant(false)]
public virtual int GetCharCount(byte* bytes, int count, bool flush);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetCharCount(byte* bytes, int count, bool flush);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual int GetCharCount(byte* bytes, int count, bool flush);
[<System.CLSCompliant(false)>]
abstract member GetCharCount : nativeptr<byte> * int * bool -> int
override this.GetCharCount : nativeptr<byte> * int * bool -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetCharCount : nativeptr<byte> * int * bool -> int
override this.GetCharCount : nativeptr<byte> * int * bool -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Security.SecurityCritical>]
abstract member GetCharCount : nativeptr<byte> * int * bool -> int
override this.GetCharCount : nativeptr<byte> * int * bool -> int
参数
- bytes
- Byte*
指向要解码的第一个字节的指针。
- count
- Int32
要解码的字节数。
- flush
- Boolean
true 模拟在计算后清除编码器的内部状态;否则,为 false.
返回
通过解码指定字节序列和内部缓冲区中的任何字节生成的字符数。
- 属性
例外
bytes 在 Visual Basic .NET 中为 null (Nothing)。
count 小于零。
注解
此方法不会影响解码器的状态。
若要计算存储生成的字符所需的确切数组大小 GetChars ,应用程序应使用 GetCharCount。
如果使用GetCharCount立即调用GetChars数据块,以便计算中包括上一个块中的任何尾随字节。
另请参阅
适用于
GetCharCount(Byte[], Int32, Int32)
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
在派生类中重写时,计算通过解码指定字节数组中的字节序列生成的字符数。
public:
abstract int GetCharCount(cli::array <System::Byte> ^ bytes, int index, int count);
public abstract int GetCharCount(byte[] bytes, int index, int count);
abstract member GetCharCount : byte[] * int * int -> int
Public MustOverride Function GetCharCount (bytes As Byte(), index As Integer, count As Integer) As Integer
参数
- bytes
- Byte[]
包含要解码的字节序列的字节数组。
- index
- Int32
要解码的第一个字节的索引。
- count
- Int32
要解码的字节数。
返回
通过解码指定字节序列和内部缓冲区中的任何字节生成的字符数。
例外
bytes 是 null (Nothing)。
示例
下面的代码示例演示如何使用 GetCharCount 该方法计算解码数组中指定字节范围所需的字符数。
using System;
using System.Text;
class DecoderExample {
public static void Main() {
Byte[] bytes = new Byte[] {
85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0
};
Decoder uniDecoder = Encoding.Unicode.GetDecoder();
int charCount = uniDecoder.GetCharCount(bytes, 0, bytes.Length);
Console.WriteLine(
"{0} characters needed to decode bytes.", charCount
);
}
}
/* This code example produces the following output.
7 characters needed to decode bytes.
*/
Imports System.Text
Class DecoderExample
Public Shared Sub Main()
Dim bytes() As Byte = { _
85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0 _
}
Dim uniDecoder As Decoder = Encoding.Unicode.GetDecoder()
Dim charCount As Integer = uniDecoder.GetCharCount(bytes, 0, bytes.Length)
Console.WriteLine("{0} characters needed to decode bytes.", charCount)
End Sub
End Class
'This code example produces the following output.
'
'7 characters needed to decode bytes.
'
注解
此方法不会影响解码器的状态。
若要计算存储生成的字符所需的确切数组大小 GetChars ,应用程序应使用 GetCharCount。
如果使用GetCharCount立即调用GetChars数据块,以便计算中包括上一个块中的任何尾随字节。
另请参阅
适用于
GetCharCount(Byte[], Int32, Int32, Boolean)
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
- Source:
- Decoder.cs
在派生类中重写时,计算通过解码指定字节数组中的字节序列生成的字符数。 参数指示是否在计算后清除解码器的内部状态。
public:
virtual int GetCharCount(cli::array <System::Byte> ^ bytes, int index, int count, bool flush);
public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush);
abstract member GetCharCount : byte[] * int * int * bool -> int
override this.GetCharCount : byte[] * int * int * bool -> int
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetCharCount : byte[] * int * int * bool -> int
override this.GetCharCount : byte[] * int * int * bool -> int
Public Overridable Function GetCharCount (bytes As Byte(), index As Integer, count As Integer, flush As Boolean) As Integer
参数
- bytes
- Byte[]
包含要解码的字节序列的字节数组。
- index
- Int32
要解码的第一个字节的索引。
- count
- Int32
要解码的字节数。
- flush
- Boolean
true 模拟在计算后清除编码器的内部状态;否则,为 false.
返回
通过解码指定字节序列和内部缓冲区中的任何字节生成的字符数。
- 属性
例外
bytes 是 null (Nothing)。
注解
此方法不会影响解码器的状态。
若要计算存储生成的字符所需的确切数组大小 GetChars ,应用程序应使用 GetCharCount。
如果使用GetCharCount立即调用GetChars数据块,以便计算中包括上一个块中的任何尾随字节。