[Serializable] |
An implementation of this class converts blocks of encoded bytes into blocks of Unicode characters through successive calls of the Decoder.GetChars method. This class maintains state information between successive calls of Decoder.GetChars, enabling it to decode a sequence of bytes that span adjacent blocks. For example, use Decoder.GetChars to decode a sequence of bytes that does not have a specific end, such as a stream.
The Decoder.GetCharCount method calculates the number of characters yielded by decoding a specified block of bytes.
Use the GetDecoder method of classes derived from the Encoding class to obtain an instance of the Decoder class.
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, e3). 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, 0xe3 }; 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+" + ((ushort)c).ToString() + " "); } }
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetCharCount | When overridden in a derived class, calculates the number of characters Decoder.GetChars would produce from decoding the specified range of bytes. |
GetChars | When overridden in a derived class, decodes a specified range of elements from a byte array and stores them in a specified range of a Unicode character array. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. Initializes a new instance of the Decoder class. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
protected Decoder(); |
~Decoder(); |
bytes
index
count
Exception Type | Condition |
---|---|
ArgumentNullException | bytes is null. |
ArgumentOutOfRangeException | index or count is less than zero. -or- index plus count is greater than the length of bytes. |
The state of the decoder is not affected by calling this method.
public abstract int GetChars( |
bytes
byteIndex
byteCount
chars
charIndex
Exception Type | Condition |
---|---|
ArgumentNullException | bytes or chars is null. |
ArgumentOutOfRangeException | byteIndex, byteCount, or charIndex is less than zero. -or- byteIndex plus byteCount is greater than the length of bytes. -or- charIndex is greater than the length of chars. |
It is recommended that you always call Decoder.GetCharCount before calling Decoder.GetChars because the Decoder.GetChars method might change the internal state information between blocks of bytes.
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |