BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates using the class to convert one character array to two byte arrays.

`using System; using System.Text; public class EncoderExample { public static void Main() { string str = "Encoder"; char[] cAry = str.ToCharArray(); UTF8Encoding utf = new UTF8Encoding(); Encoder e = utf.GetEncoder(); int count1 = e.GetByteCount(cAry,0,cAry.Length-4,false); int count2 = e.GetByteCount(cAry,cAry.Length-4,4,true); byte[] bytes1 = new byte[count1]; byte[] bytes2 = new byte[count2]; e.GetBytes(cAry,0,cAry.Length-4,bytes1,0,false); e.GetBytes(cAry,cAry.Length-4,4,bytes2,0,true); Console.Write("Bytes1: "); foreach (byte b in bytes1) Console.Write(" '{0}' ", b); Console.WriteLine(); Console.Write("Bytes2: "); foreach (byte b in bytes2) Console.Write(" '{0}' ", b); Console.WriteLine(); } }`

The output is

Bytes1: '69' '110' '99'

Bytes2: '111' '100' '101' '114'

To obtain an instance of an implementation of the class, the application should use the method of an implementation.

The method determines how many bytes result in encoding a set of Unicode characters, and the method performs the actual encoding. There are several versions of both of these methods available in the class. For more information, see .

A object maintains state information between successive calls to GetBytes or methods so that it can correctly encode character sequences that span blocks. The also preserves trailing characters at the end of data blocks and uses the trailing characters in the next encoding operation. For example, a data block might end with an unmatched high surrogate, and the matching low surrogate might be in the next data block. Therefore, and are useful for network transmission and file operations, because those operations often deal with blocks of data instead of a complete data stream.

When the application is done with a stream of data it should make sure that the state information is flushed by setting the parameter to true in the appropriate method call. If an exception occurs or if the application switches streams, it should call to clear the internal state of the Encoder object.

## Version Considerations

A or object can be serialized during a conversion operation. The state of the object is retained if it is deserialized in the same version of the .NET Framework, but lost if it is deserialized in another version.

Converts a set of characters into a sequence of bytes.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  To obtain an instance of an implementation of this class, the application should use the method of an implementation.

  Initializes a new instance of the class.

  0
- Method
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Runtime.InteropServices.ComVisible(false)
  System.Void `` `` `` `` `` `` `` `` To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(false)
  System.Void `` `` `` `` `` `` `` `` `` `` To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added. To be added.
- Property
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(false)
  System.Text.EncoderFallback To be added.

  The object represents an error handler that is invoked when a character cannot be converted into an encoded byte sequence.

  Gets or sets a object for the current object.

- Property
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(false)
  System.Text.EncoderFallbackBuffer To be added.

  The object represents data used by the object. The object represents an error handler that is invoked when a character cannot be converted into an encoded byte sequence.

  Gets the object associated with the current object.

- Method
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Runtime.InteropServices.ComVisible(false)
  System.Int32 `` `` ``

  This method does not affect the state of the encoder.

  To calculate the exact array size that requires to store the resulting bytes, the application should use .

  If GetBytes is called with set to false, the encoder stores trailing characters at the end of the data block in an internal buffer and uses them in the next encoding operation. The application should call GetByteCount on a block of data immediately before calling GetBytes on the same block, so that any trailing characters from the previous block are included in the calculation.

  When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer. A parameter indicates whether to clear the internal state of the encoder after the calculation.

  The number of bytes produced by encoding the specified characters and any characters in the internal buffer.

  A pointer to the first character to encode. The number of characters to encode. true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` `` `` `` is .

  Return value is greater than .

  -or-

  < 0.

  -or-

  < 0.

  -or-

  and do not specify a valid range in (i.e. ( + ) > .Length).

  This method does not affect the state of the encoder.

  To calculate the exact array size that requires to store the resulting bytes, the application should use .

  If GetBytes is called with set to false, the encoder stores trailing characters at the end of the data block in an internal buffer and uses them in the next encoding operation. The application should call GetByteCount on a block of data immediately before calling GetBytes on the same block, so that any trailing characters from the previous block are included in the calculation.

  When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array. A parameter indicates whether to clear the internal state of the encoder after the calculation.

  The number of bytes produced by encoding the specified characters and any characters in the internal buffer.

  The character array containing the set of characters to encode. The index of the first character to encode. The number of characters to encode. true to simulate clearing the internal state of the encoder after the calculation; otherwise, false. 0
- Method
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Runtime.InteropServices.ComVisible(false)
  System.Int32 `` `` `` `` ``

  Remember that the object saves state between calls to . When the application is done with a stream of data, it should set the parameter to true in the last call to GetBytes to make sure that the state information is flushed and that the encoded bytes are properly terminated. With this setting, the encoder ignores invalid bytes at the end of the data block, such as unmatched surrogates or incomplete combining sequences, and clears the internal buffer.

  To calculate the exact buffer size that GetBytes requires to store the resulting characters, the application should use .

  If GetBytes is called with set to false, the encoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next encoding operation. The application should call GetByteCount on a block of data immediately before calling GetBytes on the same block, so that any trailing characters from the previous block are included in the calculation.

  If your application is to convert many segments of an input stream, consider using the method. will throw an exception if the output buffer isn't large enough, but will fill as much space as possible and return the chars read and bytes written. Also see the topic for more comments.

  When overridden in a derived class, encodes a set of characters starting at the specified character pointer and any characters in the internal buffer into a sequence of bytes that are stored starting at the specified byte pointer. A parameter indicates whether to clear the internal state of the encoder after the conversion.

  The actual number of bytes written at the location indicated by the parameter.

  A pointer to the first character to encode. The number of characters to encode. A pointer to the location at which to start writing the resulting sequence of bytes. The maximum number of bytes to write. true to clear the internal state of the encoder after the conversion; otherwise, false.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` `` `` `` `` ``

  does not contain sufficient space to store the encoded characters.

  is .

  -or-

  is .

  < 0.

  -or-

  < 0.

  -or-

  < 0.

  -or-

  (.Length - ) < .

  -or-

  > .Length.

  Remember that the object saves state between calls to . When the application is done with a stream of data, it should set the parameter to true in the last call to GetBytes to make sure that the state information is flushed and that the encoded bytes are properly terminated. With this setting, the encoder ignores invalid bytes at the end of the data block, such as unmatched surrogates or incomplete combining sequences, and clears the internal buffer.

  To calculate the exact buffer size that GetBytes requires to store the resulting characters, the application should use .

  If GetBytes is called with set to false, the encoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next encoding operation. The application should call GetByteCount on a block of data immediately before calling GetBytes on the same block, so that any trailing characters from the previous block are included in the calculation.

  If your application is to convert many segments of an input stream, consider using the method. will throw an exception if the output buffer isn't large enough, but will fill as much space as possible and return the chars read and bytes written. Also see the topic for more comments.

  When overridden in a derived class, encodes a set of characters from the specified character array and any characters in the internal buffer into the specified byte array. A parameter indicates whether to clear the internal state of the encoder after the conversion.

  The actual number of bytes written into .

  The character array containing the set of characters to encode. The index of the first character to encode. The number of characters to encode. The byte array to contain the resulting sequence of bytes. The index at which to start writing the resulting sequence of bytes. true to clear the internal state of the encoder after the conversion; otherwise, false. 0
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(false)
  System.Void

  This method clears the internal state of the object. The method clears any state information preserved from a previous call to or , including trailing characters at the end of the previous data block, such as an unmatched high surrogate.

  Your application should call the Reset method if it wants to reuse the same encoder even after an exception is thrown by or , or if the application switches streams.

  When overridden in a derived class, sets the encoder back to its initial state.

0