Converts blocks of characters into blocks of bytes.
[
Edit]
See Also:
Encoder Members
[System.Runtime.InteropServices.ComVisible(true)] public abstract class Encoder |
|
Thread Safety
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
Remarks
Example
The following example demonstrates using the System.Text.UTF8Encoding class to convert one character array to two byte
arrays.
C# Example |
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'
Requirements
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0