mscorlib(4.0.0.0) API with additions
System.Text.Encoding Class Referenceabstract

Represents a character encoding.To browse the .NET Framework source code for this type, see the Reference Source. More...

Inheritance diagram for System.Text.Encoding:
[legend]
Collaboration diagram for System.Text.Encoding:
[legend]

Public Member Functions

virtual byte [] GetPreamble ()
 When overridden in a derived class, returns a sequence of bytes that specifies the encoding used. More...
 
virtual object Clone ()
 When overridden in a derived class, creates a shallow copy of the current T:System.Text.Encoding object. More...
 
virtual int GetByteCount (char[] chars)
 When overridden in a derived class, calculates the number of bytes produced by encoding all the characters in the specified character array. More...
 
virtual int GetByteCount (string s)
 When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified string. More...
 
abstract int GetByteCount (char[] chars, int index, int count)
 When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array. More...
 
virtual unsafe int GetByteCount (char *chars, int count)
 When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer. More...
 
virtual byte [] GetBytes (char[] chars)
 When overridden in a derived class, encodes all the characters in the specified character array into a sequence of bytes. More...
 
virtual byte [] GetBytes (char[] chars, int index, int count)
 When overridden in a derived class, encodes a set of characters from the specified character array into a sequence of bytes. More...
 
abstract int GetBytes (char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
 When overridden in a derived class, encodes a set of characters from the specified character array into the specified byte array. More...
 
virtual byte [] GetBytes (string s)
 When overridden in a derived class, encodes all the characters in the specified string into a sequence of bytes. More...
 
virtual int GetBytes (string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
 When overridden in a derived class, encodes a set of characters from the specified string into the specified byte array. More...
 
virtual unsafe int GetBytes (char *chars, int charCount, byte *bytes, int byteCount)
 When overridden in a derived class, encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer. More...
 
virtual int GetCharCount (byte[] bytes)
 When overridden in a derived class, calculates the number of characters produced by decoding all the bytes in the specified byte array. More...
 
abstract int GetCharCount (byte[] bytes, int index, int count)
 When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array. More...
 
virtual unsafe int GetCharCount (byte *bytes, int count)
 When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer. More...
 
virtual char [] GetChars (byte[] bytes)
 When overridden in a derived class, decodes all the bytes in the specified byte array into a set of characters. More...
 
virtual char [] GetChars (byte[] bytes, int index, int count)
 When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters. More...
 
abstract int GetChars (byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
 When overridden in a derived class, decodes a sequence of bytes from the specified byte array into the specified character array. More...
 
virtual unsafe int GetChars (byte *bytes, int byteCount, char *chars, int charCount)
 When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer. More...
 
unsafe string GetString (byte *bytes, int byteCount)
 When overridden in a derived class, decodes a specified number of bytes starting at a specified address into a string. More...
 
bool IsAlwaysNormalized ()
 Gets a value indicating whether the current encoding is always normalized, using the default normalization form. More...
 
virtual bool IsAlwaysNormalized (NormalizationForm form)
 When overridden in a derived class, gets a value indicating whether the current encoding is always normalized, using the specified normalization form. More...
 
virtual Decoder GetDecoder ()
 When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into a sequence of characters. More...
 
virtual Encoder GetEncoder ()
 When overridden in a derived class, obtains an encoder that converts a sequence of Unicode characters into an encoded sequence of bytes. More...
 
abstract int GetMaxByteCount (int charCount)
 When overridden in a derived class, calculates the maximum number of bytes produced by encoding the specified number of characters. More...
 
abstract int GetMaxCharCount (int byteCount)
 When overridden in a derived class, calculates the maximum number of characters produced by decoding the specified number of bytes. More...
 
virtual string GetString (byte[] bytes)
 When overridden in a derived class, decodes all the bytes in the specified byte array into a string. More...
 
virtual string GetString (byte[] bytes, int index, int count)
 When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a string. More...
 
override bool Equals (object value)
 Determines whether the specified T:System.Object is equal to the current instance. More...
 
override int GetHashCode ()
 Returns the hash code for the current instance. More...
 

Static Public Member Functions

static byte [] Convert (Encoding srcEncoding, Encoding dstEncoding, byte[] bytes)
 Converts an entire byte array from one encoding to another. More...
 
static byte [] Convert (Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count)
 Converts a range of bytes in a byte array from one encoding to another. More...
 
static void RegisterProvider (EncodingProvider provider)
 Registers an encoding provider. More...
 
static Encoding GetEncoding (int codepage)
 Returns the encoding associated with the specified code page identifier. More...
 
static Encoding GetEncoding (int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
 Returns the encoding associated with the specified code page identifier. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded. More...
 
static Encoding GetEncoding (string name)
 Returns the encoding associated with the specified code page name. More...
 
static Encoding GetEncoding (string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
 Returns the encoding associated with the specified code page name. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded. More...
 
static EncodingInfo [] GetEncodings ()
 Returns an array that contains all encodings. More...
 

Protected Member Functions

 Encoding ()
 Initializes a new instance of the T:System.Text.Encoding class. More...
 
 Encoding (int codePage)
 Initializes a new instance of the T:System.Text.Encoding class that corresponds to the specified code page. More...
 
 Encoding (int codePage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
 Initializes a new instance of the T:System.Text.Encoding class that corresponds to the specified code page with the specified encoder and decoder fallback strategies. More...
 

Properties

virtual string BodyName [get]
 When overridden in a derived class, gets a name for the current encoding that can be used with mail agent body tags. More...
 
virtual string EncodingName [get]
 When overridden in a derived class, gets the human-readable description of the current encoding. More...
 
virtual string HeaderName [get]
 When overridden in a derived class, gets a name for the current encoding that can be used with mail agent header tags. More...
 
virtual string WebName [get]
 When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding. More...
 
virtual int WindowsCodePage [get]
 When overridden in a derived class, gets the Windows operating system code page that most closely corresponds to the current encoding. More...
 
virtual bool IsBrowserDisplay [get]
 When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for displaying content. More...
 
virtual bool IsBrowserSave [get]
 When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for saving content. More...
 
virtual bool IsMailNewsDisplay [get]
 When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for displaying content. More...
 
virtual bool IsMailNewsSave [get]
 When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for saving content. More...
 
virtual bool IsSingleByte [get]
 When overridden in a derived class, gets a value indicating whether the current encoding uses single-byte code points. More...
 
EncoderFallback EncoderFallback [get, set]
 Gets or sets the T:System.Text.EncoderFallback object for the current T:System.Text.Encoding object. More...
 
DecoderFallback DecoderFallback [get, set]
 Gets or sets the T:System.Text.DecoderFallback object for the current T:System.Text.Encoding object. More...
 
bool IsReadOnly [get]
 When overridden in a derived class, gets a value indicating whether the current encoding is read-only. More...
 
static Encoding ASCII [get]
 Gets an encoding for the ASCII (7-bit) character set. More...
 
virtual int CodePage [get]
 When overridden in a derived class, gets the code page identifier of the current T:System.Text.Encoding. More...
 
static Encoding Default [get]
 Gets an encoding for the operating system's current ANSI code page. More...
 
static Encoding Unicode [get]
 Gets an encoding for the UTF-16 format using the little endian byte order. More...
 
static Encoding BigEndianUnicode [get]
 Gets an encoding for the UTF-16 format that uses the big endian byte order. More...
 
static Encoding UTF7 [get]
 Gets an encoding for the UTF-7 format. More...
 
static Encoding UTF8 [get]
 Gets an encoding for the UTF-8 format. More...
 
static Encoding UTF32 [get]
 Gets an encoding for the UTF-32 format using the little endian byte order. More...
 

Detailed Description

Represents a character encoding.To browse the .NET Framework source code for this type, see the Reference Source.

Definition at line 15 of file Encoding.cs.

Constructor & Destructor Documentation

◆ Encoding() [1/3]

System.Text.Encoding.Encoding ( )
protected

Initializes a new instance of the T:System.Text.Encoding class.

Definition at line 1053 of file Encoding.cs.

◆ Encoding() [2/3]

System.Text.Encoding.Encoding ( int  codePage)
protected

Initializes a new instance of the T:System.Text.Encoding class that corresponds to the specified code page.

Parameters
codePageThe code page identifier of the preferred encoding.-or- 0, to use the default encoding.
Exceptions
T:System.ArgumentOutOfRangeExceptioncodePage is less than zero.

Definition at line 1063 of file Encoding.cs.

◆ Encoding() [3/3]

System.Text.Encoding.Encoding ( int  codePage,
EncoderFallback  encoderFallback,
DecoderFallback  decoderFallback 
)
protected

Initializes a new instance of the T:System.Text.Encoding class that corresponds to the specified code page with the specified encoder and decoder fallback strategies.

Parameters
codePageThe encoding code page identifier.
encoderFallbackAn object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
decoderFallbackAn object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.
Exceptions
T:System.ArgumentOutOfRangeExceptioncodePage is less than zero.

Definition at line 1080 of file Encoding.cs.

Member Function Documentation

◆ Clone()

virtual object System.Text.Encoding.Clone ( )
virtual

When overridden in a derived class, creates a shallow copy of the current T:System.Text.Encoding object.

Returns
A copy of the current T:System.Text.Encoding object.

Implements System.ICloneable.

Definition at line 1474 of file Encoding.cs.

◆ Convert() [1/2]

static byte [] System.Text.Encoding.Convert ( Encoding  srcEncoding,
Encoding  dstEncoding,
byte []  bytes 
)
static

Converts an entire byte array from one encoding to another.

Parameters
srcEncodingThe encoding format of bytes .
dstEncodingThe target encoding format.
bytesThe bytes to convert.
Returns
An array of type T:System.Byte containing the results of converting bytes from srcEncoding to dstEncoding .
Exceptions
T:System.ArgumentNullExceptionsrcEncoding is null.-or- dstEncoding is null.-or- bytes is null.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- srcEncoding. P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- dstEncoding. P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Definition at line 1185 of file Encoding.cs.

◆ Convert() [2/2]

static byte [] System.Text.Encoding.Convert ( Encoding  srcEncoding,
Encoding  dstEncoding,
byte []  bytes,
int  index,
int  count 
)
static

Converts a range of bytes in a byte array from one encoding to another.

Parameters
srcEncodingThe encoding of the source array, bytes .
dstEncodingThe encoding of the output array.
bytesThe array of bytes to convert.
indexThe index of the first element of bytes to convert.
countThe number of bytes to convert.
Returns
An array of type T:System.Byte containing the result of converting a range of bytes in bytes from srcEncoding to dstEncoding .
Exceptions
T:System.ArgumentNullExceptionsrcEncoding is null.-or- dstEncoding is null.-or- bytes is null.
T:System.ArgumentOutOfRangeExceptionindex and count do not specify a valid range in the byte array.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- srcEncoding. P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- dstEncoding. P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Definition at line 1214 of file Encoding.cs.

◆ Equals()

override bool System.Text.Encoding.Equals ( object  value)

Determines whether the specified T:System.Object is equal to the current instance.

Parameters
valueThe T:System.Object to compare with the current instance.
Returns
true if value is an instance of T:System.Text.Encoding and is equal to the current instance; otherwise, false.

Definition at line 2039 of file Encoding.cs.

◆ GetByteCount() [1/4]

virtual int System.Text.Encoding.GetByteCount ( char []  chars)
virtual

When overridden in a derived class, calculates the number of bytes produced by encoding all the characters in the specified character array.

Parameters
charsThe character array containing the characters to encode.
Returns
The number of bytes produced by encoding all the characters in the specified character array.
Exceptions
T:System.ArgumentNullExceptionchars is null.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Definition at line 1489 of file Encoding.cs.

◆ GetByteCount() [2/4]

virtual int System.Text.Encoding.GetByteCount ( string  s)
virtual

When overridden in a derived class, calculates the number of bytes produced by encoding the characters in the specified string.

Parameters
sThe string containing the set of characters to encode.
Returns
The number of bytes produced by encoding the specified characters.
Exceptions
T:System.ArgumentNullExceptions is null.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 1506 of file Encoding.cs.

◆ GetByteCount() [3/4]

abstract int System.Text.Encoding.GetByteCount ( char []  chars,
int  index,
int  count 
)
pure virtual

When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array.

Parameters
charsThe character array containing the set of characters to encode.
indexThe index of the first character to encode.
countThe number of characters to encode.
Returns
The number of bytes produced by encoding the specified characters.
Exceptions
T:System.ArgumentNullExceptionchars is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.-or- index and count do not denote a valid range in chars .
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Implemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

◆ GetByteCount() [4/4]

virtual unsafe int System.Text.Encoding.GetByteCount ( char *  chars,
int  count 
)
virtual

When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer.

Parameters
charsA pointer to the first character to encode.
countThe number of characters to encode.
Returns
The number of bytes produced by encoding the specified characters.
Exceptions
T:System.ArgumentNullExceptionchars is null.
T:System.ArgumentOutOfRangeExceptioncount is less than zero.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 1544 of file Encoding.cs.

◆ GetBytes() [1/6]

virtual byte [] System.Text.Encoding.GetBytes ( char []  chars)
virtual

When overridden in a derived class, encodes all the characters in the specified character array into a sequence of bytes.

Parameters
charsThe character array containing the characters to encode.
Returns
A byte array containing the results of encoding the specified set of characters.
Exceptions
T:System.ArgumentNullExceptionchars is null.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Definition at line 1576 of file Encoding.cs.

◆ GetBytes() [2/6]

virtual byte [] System.Text.Encoding.GetBytes ( char []  chars,
int  index,
int  count 
)
virtual

When overridden in a derived class, encodes a set of characters from the specified character array into a sequence of bytes.

Parameters
charsThe character array containing the set of characters to encode.
indexThe index of the first character to encode.
countThe number of characters to encode.
Returns
A byte array containing the results of encoding the specified set of characters.
Exceptions
T:System.ArgumentNullExceptionchars is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.-or- index and count do not denote a valid range in chars .
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Definition at line 1598 of file Encoding.cs.

◆ GetBytes() [3/6]

abstract int System.Text.Encoding.GetBytes ( char []  chars,
int  charIndex,
int  charCount,
byte []  bytes,
int  byteIndex 
)
pure virtual

When overridden in a derived class, encodes a set of characters from the specified character array into the specified byte array.

Parameters
charsThe character array containing the set of characters to encode.
charIndexThe index of the first character to encode.
charCountThe number of characters to encode.
bytesThe byte array to contain the resulting sequence of bytes.
byteIndexThe index at which to start writing the resulting sequence of bytes.
Returns
The actual number of bytes written into bytes .
Exceptions
T:System.ArgumentNullExceptionchars is null.-or- bytes is null.
T:System.ArgumentOutOfRangeExceptioncharIndex or charCount or byteIndex is less than zero.-or- charIndex and charCount do not denote a valid range in chars .-or- byteIndex is not a valid index in bytes .
T:System.ArgumentExceptionbytes does not have enough capacity from byteIndex to the end of the array to accommodate the resulting bytes.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Implemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

◆ GetBytes() [4/6]

virtual byte [] System.Text.Encoding.GetBytes ( string  s)
virtual

When overridden in a derived class, encodes all the characters in the specified string into a sequence of bytes.

Parameters
sThe string containing the characters to encode.
Returns
A byte array containing the results of encoding the specified set of characters.
Exceptions
T:System.ArgumentNullExceptions is null.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Definition at line 1634 of file Encoding.cs.

◆ GetBytes() [5/6]

virtual int System.Text.Encoding.GetBytes ( string  s,
int  charIndex,
int  charCount,
byte []  bytes,
int  byteIndex 
)
virtual

When overridden in a derived class, encodes a set of characters from the specified string into the specified byte array.

Parameters
sThe string containing the set of characters to encode.
charIndexThe index of the first character to encode.
charCountThe number of characters to encode.
bytesThe byte array to contain the resulting sequence of bytes.
byteIndexThe index at which to start writing the resulting sequence of bytes.
Returns
The actual number of bytes written into bytes .
Exceptions
T:System.ArgumentNullExceptions is null.-or- bytes is null.
T:System.ArgumentOutOfRangeExceptioncharIndex or charCount or byteIndex is less than zero.-or- charIndex and charCount do not denote a valid range in chars .-or- byteIndex is not a valid index in bytes .
T:System.ArgumentExceptionbytes does not have enough capacity from byteIndex to the end of the array to accommodate the resulting bytes.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 1665 of file Encoding.cs.

◆ GetBytes() [6/6]

virtual unsafe int System.Text.Encoding.GetBytes ( char *  chars,
int  charCount,
byte *  bytes,
int  byteCount 
)
virtual

When overridden in a derived class, encodes a set of characters starting at the specified character pointer into a sequence of bytes that are stored starting at the specified byte pointer.

Parameters
charsA pointer to the first character to encode.
charCountThe number of characters to encode.
bytesA pointer to the location at which to start writing the resulting sequence of bytes.
byteCountThe maximum number of bytes to write.
Returns
The actual number of bytes written at the location indicated by the bytes parameter.
Exceptions
T:System.ArgumentNullExceptionchars is null.-or- bytes is null.
T:System.ArgumentOutOfRangeExceptioncharCount or byteCount is less than zero.
T:System.ArgumentExceptionbyteCount is less than the resulting number of bytes.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 1698 of file Encoding.cs.

◆ GetCharCount() [1/3]

virtual int System.Text.Encoding.GetCharCount ( byte []  bytes)
virtual

When overridden in a derived class, calculates the number of characters produced by decoding all the bytes in the specified byte array.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
Returns
The number of characters produced by decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentNullExceptionbytes is null.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Definition at line 1734 of file Encoding.cs.

◆ GetCharCount() [2/3]

abstract int System.Text.Encoding.GetCharCount ( byte []  bytes,
int  index,
int  count 
)
pure virtual

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
indexThe index of the first byte to decode.
countThe number of bytes to decode.
Returns
The number of characters produced by decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentNullExceptionbytes is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.-or- index and count do not denote a valid range in bytes .
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Implemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

◆ GetCharCount() [3/3]

virtual unsafe int System.Text.Encoding.GetCharCount ( byte *  bytes,
int  count 
)
virtual

When overridden in a derived class, calculates the number of characters produced by decoding a sequence of bytes starting at the specified byte pointer.

Parameters
bytesA pointer to the first byte to decode.
countThe number of bytes to decode.
Returns
The number of characters produced by decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentNullExceptionbytes is null.
T:System.ArgumentOutOfRangeExceptioncount is less than zero.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 1771 of file Encoding.cs.

◆ GetChars() [1/4]

virtual char [] System.Text.Encoding.GetChars ( byte []  bytes)
virtual

When overridden in a derived class, decodes all the bytes in the specified byte array into a set of characters.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
Returns
A character array containing the results of decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentNullExceptionbytes is null.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Definition at line 1803 of file Encoding.cs.

◆ GetChars() [2/4]

virtual char [] System.Text.Encoding.GetChars ( byte []  bytes,
int  index,
int  count 
)
virtual

When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a set of characters.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
indexThe index of the first byte to decode.
countThe number of bytes to decode.
Returns
A character array containing the results of decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentNullExceptionbytes is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.-or- index and count do not denote a valid range in bytes .
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Definition at line 1825 of file Encoding.cs.

◆ GetChars() [3/4]

abstract int System.Text.Encoding.GetChars ( byte []  bytes,
int  byteIndex,
int  byteCount,
char []  chars,
int  charIndex 
)
pure virtual

When overridden in a derived class, decodes a sequence of bytes from the specified byte array into the specified character array.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
byteIndexThe index of the first byte to decode.
byteCountThe number of bytes to decode.
charsThe character array to contain the resulting set of characters.
charIndexThe index at which to start writing the resulting set of characters.
Returns
The actual number of characters written into chars .
Exceptions
T:System.ArgumentNullExceptionbytes is null.-or- chars is null.
T:System.ArgumentOutOfRangeExceptionbyteIndex or byteCount or charIndex is less than zero.-or- byteindex and byteCount do not denote a valid range in bytes .-or- charIndex is not a valid index in chars .
T:System.ArgumentExceptionchars does not have enough capacity from charIndex to the end of the array to accommodate the resulting characters.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Implemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

◆ GetChars() [4/4]

virtual unsafe int System.Text.Encoding.GetChars ( byte *  bytes,
int  byteCount,
char *  chars,
int  charCount 
)
virtual

When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are stored starting at the specified character pointer.

Parameters
bytesA pointer to the first byte to decode.
byteCountThe number of bytes to decode.
charsA pointer to the location at which to start writing the resulting set of characters.
charCountThe maximum number of characters to write.
Returns
The actual number of characters written at the location indicated by the chars parameter.
Exceptions
T:System.ArgumentNullExceptionbytes is null.-or- chars is null.
T:System.ArgumentOutOfRangeExceptionbyteCount or charCount is less than zero.
T:System.ArgumentExceptioncharCount is less than the resulting number of characters.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 1871 of file Encoding.cs.

◆ GetDecoder()

virtual Decoder System.Text.Encoding.GetDecoder ( )
virtual

When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into a sequence of characters.

Returns
A T:System.Text.Decoder that converts an encoded sequence of bytes into a sequence of characters.

Reimplemented in System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, System.Text.UTF7Encoding, and System.Text.ASCIIEncoding.

Definition at line 1953 of file Encoding.cs.

◆ GetEncoder()

virtual Encoder System.Text.Encoding.GetEncoder ( )
virtual

When overridden in a derived class, obtains an encoder that converts a sequence of Unicode characters into an encoded sequence of bytes.

Returns
A T:System.Text.Encoder that converts a sequence of Unicode characters into an encoded sequence of bytes.

Reimplemented in System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, System.Text.UTF7Encoding, and System.Text.ASCIIEncoding.

Definition at line 1972 of file Encoding.cs.

◆ GetEncoding() [1/4]

static Encoding System.Text.Encoding.GetEncoding ( int  codepage)
static

Returns the encoding associated with the specified code page identifier.

Parameters
codepageThe code page identifier of the preferred encoding. Possible values are listed in the Code Page column of the table that appears in the T:System.Text.Encoding class topic.-or- 0 (zero), to use the default encoding.
Returns
The encoding that is associated with the specified code page.
Exceptions
T:System.ArgumentOutOfRangeExceptioncodepage is less than zero or greater than 65535.
T:System.ArgumentExceptioncodepage is not supported by the underlying platform.
T:System.NotSupportedExceptioncodepage is not supported by the underlying platform.

Definition at line 1249 of file Encoding.cs.

◆ GetEncoding() [2/4]

static Encoding System.Text.Encoding.GetEncoding ( int  codepage,
EncoderFallback  encoderFallback,
DecoderFallback  decoderFallback 
)
static

Returns the encoding associated with the specified code page identifier. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

Parameters
codepageThe code page identifier of the preferred encoding. Possible values are listed in the Code Page column of the table that appears in the T:System.Text.Encoding class topic.-or- 0 (zero), to use the default encoding.
encoderFallbackAn object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
decoderFallbackAn object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.
Returns
The encoding that is associated with the specified code page.
Exceptions
T:System.ArgumentOutOfRangeExceptioncodepage is less than zero or greater than 65535.
T:System.ArgumentExceptioncodepage is not supported by the underlying platform.
T:System.NotSupportedExceptioncodepage is not supported by the underlying platform.

Definition at line 1331 of file Encoding.cs.

◆ GetEncoding() [3/4]

static Encoding System.Text.Encoding.GetEncoding ( string  name)
static

Returns the encoding associated with the specified code page name.

Parameters
nameThe code page name of the preferred encoding. Any value returned by the P:System.Text.Encoding.WebName property is valid. Possible values are listed in the Name column of the table that appears in the T:System.Text.Encoding class topic.
Returns
The encoding associated with the specified code page.
Exceptions
T:System.ArgumentExceptionname is not a valid code page name.-or- The code page indicated by name is not supported by the underlying platform.

Definition at line 1415 of file Encoding.cs.

◆ GetEncoding() [4/4]

static Encoding System.Text.Encoding.GetEncoding ( string  name,
EncoderFallback  encoderFallback,
DecoderFallback  decoderFallback 
)
static

Returns the encoding associated with the specified code page name. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

Parameters
nameThe code page name of the preferred encoding. Any value returned by the P:System.Text.Encoding.WebName property is valid. Possible values are listed in the Name column of the table that appears in the T:System.Text.Encoding class topic.
encoderFallbackAn object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
decoderFallbackAn object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.
Returns
The encoding that is associated with the specified code page.
Exceptions
T:System.ArgumentExceptionname is not a valid code page name.-or- The code page indicated by name is not supported by the underlying platform.

Definition at line 1433 of file Encoding.cs.

◆ GetEncodings()

static EncodingInfo [] System.Text.Encoding.GetEncodings ( )
static

Returns an array that contains all encodings.

Returns
An array that contains all encodings.

Definition at line 1445 of file Encoding.cs.

◆ GetHashCode()

override int System.Text.Encoding.GetHashCode ( )

Returns the hash code for the current instance.

Returns
The hash code for the current instance.

Definition at line 2056 of file Encoding.cs.

◆ GetMaxByteCount()

abstract int System.Text.Encoding.GetMaxByteCount ( int  charCount)
pure virtual

When overridden in a derived class, calculates the maximum number of bytes produced by encoding the specified number of characters.

Parameters
charCountThe number of characters to encode.
Returns
The maximum number of bytes produced by encoding the specified number of characters.
Exceptions
T:System.ArgumentOutOfRangeExceptioncharCount is less than zero.
T:System.Text.EncoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.EncoderFallback is set to T:System.Text.EncoderExceptionFallback.

Implemented in System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, System.Text.UTF7Encoding, and System.Text.ASCIIEncoding.

◆ GetMaxCharCount()

abstract int System.Text.Encoding.GetMaxCharCount ( int  byteCount)
pure virtual

When overridden in a derived class, calculates the maximum number of characters produced by decoding the specified number of bytes.

Parameters
byteCountThe number of bytes to decode.
Returns
The maximum number of characters produced by decoding the specified number of bytes.
Exceptions
T:System.ArgumentOutOfRangeExceptionbyteCount is less than zero.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Implemented in System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, System.Text.UTF7Encoding, and System.Text.ASCIIEncoding.

◆ GetPreamble()

virtual byte [] System.Text.Encoding.GetPreamble ( )
virtual

When overridden in a derived class, returns a sequence of bytes that specifies the encoding used.

Returns
A byte array containing a sequence of bytes that specifies the encoding used.-or- A byte array of length zero, if a preamble is not required.

Reimplemented in System.Text.UTF8Encoding, System.Text.UnicodeEncoding, and System.Text.UTF32Encoding.

Definition at line 1453 of file Encoding.cs.

◆ GetString() [1/3]

unsafe string System.Text.Encoding.GetString ( byte *  bytes,
int  byteCount 
)

When overridden in a derived class, decodes a specified number of bytes starting at a specified address into a string.

Parameters
bytesA pointer to a byte array.
byteCountThe number of bytes to decode.
Returns
A string that contains the results of decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentNullExceptionbytes is a null pointer.
T:System.ArgumentOutOfRangeExceptionbyteCount is less than zero.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for a complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Definition at line 1918 of file Encoding.cs.

◆ GetString() [2/3]

virtual string System.Text.Encoding.GetString ( byte []  bytes)
virtual

When overridden in a derived class, decodes all the bytes in the specified byte array into a string.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
Returns
A string that contains the results of decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentExceptionThe byte array contains invalid Unicode code points.
T:System.ArgumentNullExceptionbytes is null.
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Definition at line 2006 of file Encoding.cs.

◆ GetString() [3/3]

virtual string System.Text.Encoding.GetString ( byte []  bytes,
int  index,
int  count 
)
virtual

When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a string.

Parameters
bytesThe byte array containing the sequence of bytes to decode.
indexThe index of the first byte to decode.
countThe number of bytes to decode.
Returns
A string that contains the results of decoding the specified sequence of bytes.
Exceptions
T:System.ArgumentExceptionThe byte array contains invalid Unicode code points.
T:System.ArgumentNullExceptionbytes is null.
T:System.ArgumentOutOfRangeExceptionindex or count is less than zero.-or- index and count do not denote a valid range in bytes .
T:System.Text.DecoderFallbackExceptionA fallback occurred (see Character Encoding in the .NET Framework for complete explanation)-and- P:System.Text.Encoding.DecoderFallback is set to T:System.Text.DecoderExceptionFallback.

Reimplemented in System.Text.UTF7Encoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and System.Text.ASCIIEncoding.

Definition at line 2029 of file Encoding.cs.

◆ IsAlwaysNormalized() [1/2]

bool System.Text.Encoding.IsAlwaysNormalized ( )

Gets a value indicating whether the current encoding is always normalized, using the default normalization form.

Returns
true if the current T:System.Text.Encoding is always normalized; otherwise, false. The default is false.

Definition at line 1935 of file Encoding.cs.

◆ IsAlwaysNormalized() [2/2]

virtual bool System.Text.Encoding.IsAlwaysNormalized ( NormalizationForm  form)
virtual

When overridden in a derived class, gets a value indicating whether the current encoding is always normalized, using the specified normalization form.

Parameters
formOne of the T:System.Text.NormalizationForm values.
Returns
true if the current T:System.Text.Encoding object is always normalized using the specified T:System.Text.NormalizationForm value; otherwise, false. The default is false.

Definition at line 1945 of file Encoding.cs.

◆ RegisterProvider()

static void System.Text.Encoding.RegisterProvider ( EncodingProvider  provider)
static

Registers an encoding provider.

Parameters
providerA subclass of T:System.Text.EncodingProvider that provides access to additional character encodings.
Exceptions
T:System.ArgumentNullExceptionprovider is null.

Definition at line 1233 of file Encoding.cs.

Property Documentation

◆ ASCII

Encoding System.Text.Encoding.ASCII
staticget

Gets an encoding for the ASCII (7-bit) character set.

Returns
An encoding for the ASCII (7-bit) character set.

Definition at line 920 of file Encoding.cs.

◆ BigEndianUnicode

Encoding System.Text.Encoding.BigEndianUnicode
staticget

Gets an encoding for the UTF-16 format that uses the big endian byte order.

Returns
An encoding object for the UTF-16 format that uses the big endian byte order.

Definition at line 991 of file Encoding.cs.

◆ BodyName

virtual string System.Text.Encoding.BodyName
get

When overridden in a derived class, gets a name for the current encoding that can be used with mail agent body tags.

Returns
A name for the current T:System.Text.Encoding that can be used with mail agent body tags.-or- An empty string (""), if the current T:System.Text.Encoding cannot be used.

Definition at line 709 of file Encoding.cs.

◆ CodePage

virtual int System.Text.Encoding.CodePage
get

When overridden in a derived class, gets the code page identifier of the current T:System.Text.Encoding.

Returns
The code page identifier of the current T:System.Text.Encoding.

Definition at line 948 of file Encoding.cs.

◆ DecoderFallback

DecoderFallback System.Text.Encoding.DecoderFallback
getset

Gets or sets the T:System.Text.DecoderFallback object for the current T:System.Text.Encoding object.

Returns
The decoder fallback object for the current T:System.Text.Encoding object.
Exceptions
T:System.ArgumentNullExceptionThe value in a set operation is null.
T:System.InvalidOperationExceptionA value cannot be assigned in a set operation because the current T:System.Text.Encoding object is read-only.

Definition at line 884 of file Encoding.cs.

◆ Default

Encoding System.Text.Encoding.Default
staticget

Gets an encoding for the operating system's current ANSI code page.

Returns
An encoding for the operating system's current ANSI code page.

Definition at line 959 of file Encoding.cs.

◆ EncoderFallback

EncoderFallback System.Text.Encoding.EncoderFallback
getset

Gets or sets the T:System.Text.EncoderFallback object for the current T:System.Text.Encoding object.

Returns
The encoder fallback object for the current T:System.Text.Encoding object.
Exceptions
T:System.ArgumentNullExceptionThe value in a set operation is null.
T:System.InvalidOperationExceptionA value cannot be assigned in a set operation because the current T:System.Text.Encoding object is read-only.

Definition at line 857 of file Encoding.cs.

◆ EncodingName

virtual string System.Text.Encoding.EncodingName
get

When overridden in a derived class, gets the human-readable description of the current encoding.

Returns
The human-readable description of the current T:System.Text.Encoding.

Definition at line 724 of file Encoding.cs.

◆ HeaderName

virtual string System.Text.Encoding.HeaderName
get

When overridden in a derived class, gets a name for the current encoding that can be used with mail agent header tags.

Returns
A name for the current T:System.Text.Encoding to use with mail agent header tags.-or- An empty string (""), if the current T:System.Text.Encoding cannot be used.

Definition at line 735 of file Encoding.cs.

◆ IsBrowserDisplay

virtual bool System.Text.Encoding.IsBrowserDisplay
get

When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for displaying content.

Returns
true if the current T:System.Text.Encoding can be used by browser clients for displaying content; otherwise, false.

Definition at line 780 of file Encoding.cs.

◆ IsBrowserSave

virtual bool System.Text.Encoding.IsBrowserSave
get

When overridden in a derived class, gets a value indicating whether the current encoding can be used by browser clients for saving content.

Returns
true if the current T:System.Text.Encoding can be used by browser clients for saving content; otherwise, false.

Definition at line 795 of file Encoding.cs.

◆ IsMailNewsDisplay

virtual bool System.Text.Encoding.IsMailNewsDisplay
get

When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for displaying content.

Returns
true if the current T:System.Text.Encoding can be used by mail and news clients for displaying content; otherwise, false.

Definition at line 810 of file Encoding.cs.

◆ IsMailNewsSave

virtual bool System.Text.Encoding.IsMailNewsSave
get

When overridden in a derived class, gets a value indicating whether the current encoding can be used by mail and news clients for saving content.

Returns
true if the current T:System.Text.Encoding can be used by mail and news clients for saving content; otherwise, false.

Definition at line 825 of file Encoding.cs.

◆ IsReadOnly

bool System.Text.Encoding.IsReadOnly
get

When overridden in a derived class, gets a value indicating whether the current encoding is read-only.

Returns
true if the current T:System.Text.Encoding is read-only; otherwise, false. The default is true.

Definition at line 909 of file Encoding.cs.

◆ IsSingleByte

virtual bool System.Text.Encoding.IsSingleByte
get

When overridden in a derived class, gets a value indicating whether the current encoding uses single-byte code points.

Returns
true if the current T:System.Text.Encoding uses single-byte code points; otherwise, false.

Definition at line 842 of file Encoding.cs.

◆ Unicode

Encoding System.Text.Encoding.Unicode
staticget

Gets an encoding for the UTF-16 format using the little endian byte order.

Returns
An encoding for the UTF-16 format using the little endian byte order.

Definition at line 975 of file Encoding.cs.

◆ UTF32

Encoding System.Text.Encoding.UTF32
staticget

Gets an encoding for the UTF-32 format using the little endian byte order.

Returns
An encoding object for the UTF-32 format using the little endian byte order.

Definition at line 1039 of file Encoding.cs.

◆ UTF7

Encoding System.Text.Encoding.UTF7
staticget

Gets an encoding for the UTF-7 format.

Returns
An encoding for the UTF-7 format.

Definition at line 1007 of file Encoding.cs.

◆ UTF8

Encoding System.Text.Encoding.UTF8
staticget

Gets an encoding for the UTF-8 format.

Returns
An encoding for the UTF-8 format.

Definition at line 1023 of file Encoding.cs.

◆ WebName

virtual string System.Text.Encoding.WebName
get

When overridden in a derived class, gets the name registered with the Internet Assigned Numbers Authority (IANA) for the current encoding.

Returns
The IANA name for the current T:System.Text.Encoding.

Definition at line 750 of file Encoding.cs.

◆ WindowsCodePage

virtual int System.Text.Encoding.WindowsCodePage
get

When overridden in a derived class, gets the Windows operating system code page that most closely corresponds to the current encoding.

Returns
The Windows operating system code page that most closely corresponds to the current T:System.Text.Encoding.

Definition at line 765 of file Encoding.cs.


The documentation for this class was generated from the following file: