複製鏈接
請複製以下鏈接發送給好友

decoder

鎖定
decoder,計算機語言函數,意思是將編碼字節序列轉換為一組字符
外文名
decoder
解    釋
將編碼字節序列轉換為一組字符
命名空間
System.Text
程序集
mscorlib(在 mscorlib.dll 中)

目錄

  1. 1 語法
  2. C#
  3. C++
  1. VB
  2. 2 其他信息
  3. 3 示例
  1. c#
  2. C++

decoder語法

decoderC#

[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class Decoder

decoderC++

[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class Decoder abstract

decoderVB

聲明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public MustInherit Class Decoder
用法
Dim instance As Decoder

decoder其他信息

編碼是將一組字符轉換為一個字節序列的過程。解碼是一個反向操作過程,即將一個編碼字節序列轉換為一組字符。
Decoder 在連續調用 GetChars 之間維護狀態信息,因此它可以正確地對跨塊的字節序列進行解碼。Decoder 還保留數據塊結尾的尾部字節並將這些尾部字節用在下一次解碼操作中。因此,GetDecoder 和 GetEncoder 在網絡傳輸和文件操作中很有用,這是因為這些操作通常處理數據塊而不是完整的數據流。
GetCharCount 方法確定有多少字符導致對字節序列進行解碼,而 GetChars 方法執行實際的解碼。
若要獲得此類某個實現的實例,請使用 Encoding 實現的 GetDecoder 方法。
版本注意事項
轉換操作期間可以序列化 Decoder 或 Encoder 對象。如果在相同版本的 .NET Framework 中反序列化對象,則保留對象的狀態,但如果在另一個版本中反序列化對象,則對象的狀態會丟失。
給繼承者的説明 從此類繼承時,您必須重寫所有成員。

decoder示例

decoderc#

using System;
using System.Text;
public class dec
{
public static void Main()
{
// These bytes in UTF-8 correspond to 3 different Unicode
// characters: space (U+0020), # (U+0023), and the biohazard
// symbol (U+2623). Note the biohazard symbol requires 3 bytes
// in UTF-8 (hexadecimal e2, 98, a3). Decoders store state across
// multiple calls to GetChars, handling the case when one char
// is in multiple byte arrays.
byte[] bytes1 = { 0x20, 0x23, 0xe2 };
byte[] bytes2 = { 0x98, 0xa3 };
char[] chars = new char[3];
Decoder d = Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(bytes1, 0, bytes1.Length, chars, 0);
// The value of charLen should be 2 now.
charLen += d.GetChars(bytes2, 0, bytes2.Length, chars, charLen);
foreach(char c in chars)
Console.Write("U+{0:X4} ", (ushort)c);
}
}

decoderC++

using namespace System;
using namespace System::Text;
int main()
{
// These bytes in UTF-8 correspond to 3 different Unicode
// characters: space (U+0020), # (U+0023), and the biohazard
// symbol (U+2623). Note the biohazard symbol requires 3 bytes
// in UTF-8 (hexadecimal e2, 98, a3). Decoders store state across
// multiple calls to GetChars, handling the case when one char
// is in multiple byte arrays. array<Byte>^bytes1 = {0x20,0x23,0xe2};
array<Byte>^bytes2 = {0x98,0xa3};
array<Char>^chars = gcnew array<Char>(3);
Decoder^ d = Encoding::UTF8->GetDecoder();
int charLen = d->GetChars( bytes1, 0, bytes1->Length, chars, 0 );
// The value of charLen should be 2 now.
charLen += d->GetChars( bytes2, 0, bytes2->Length, chars, charLen );
for ( UInt16 index(0); index < chars->Length; ++index )
{
Console::Write( "U+{0:X4} ", static_cast<UInt16>(chars[ index ]) );
}
} [1] 
參考資料