O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Encoder

Synopsis

Encoding.GetEncoder() returns an instance of this type, which converts character arrays to byte arrays using the encoding subclass from which it was constructed. This class exposes the GetBytes() method, which converts a sequence of character blocks into a sequence of byte blocks. Since Encoder maintains state between calls to GetBytes(), it can deal with partial sequences that occur at block boundaries.

The last argument to GetBytes() is a boolean that specifies whether the internal buffer is flushed after the method is called. If true, state information on the object is lost between blocks. If false (the default), the buffer is maintained. A call with flushing set to true is needed on the final call to Encoding.GetBytes() to close the byte array properly.

public abstract class Encoder {
// Protected Constructors
   protected method Encoder();  
// Public Instance Methods
   public abstract method int GetByteCount(char[] chars, 
        int index, int count, bool flush);  
   public abstract method int GetBytes(char[] chars, 
        int charIndex, int charCount, byte[] bytes, 
        int byteIndex, bool flush);  
}

Returned By

Encoding.GetEncoder()

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required