System.Text.ASCIIEncoding Class

Assembly: Mscorlib.dll
Namespace: System.Text
Summary
Represents an ASCII character encoding of Unicode characters.
C# Syntax:
[Serializable]
public class ASCIIEncoding : Encoding
Remarks
ASCIIEncoding encodes Unicode characters as single 7-bit ASCII characters. This encoding only supports character values between U+0000 and U+007F. This limitation makes ASCII largely inadequate for internationalized applications. Consider using UTF8Encoding or UnicodeEncoding instead.

The Windows code page that corresponds to ASCIIEncoding is 20127.

This class inherits from the Encoding class.

See also:
System.Text Namespace

System.Text.ASCIIEncoding Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the ASCIIEncoding class.
Public Properties
BodyName
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.BodyName


Gets the name for this encoding that can be used with mail agent body tags.
CodePage
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.CodePage


When overridden in a derived class, gets the code page identifier of this encoding.
EncodingName
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.EncodingName


Gets the human-readable description of the encoding.
HeaderName
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.HeaderName


Gets the name for this encoding that can be used with mail agent header tags.
IsBrowserDisplay
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.IsBrowserDisplay


Gets an indication whether this encoding can be used for display by browser clients.
IsBrowserSave
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.IsBrowserSave


Gets an indication whether this encoding can be used for saving by browser clients.
IsMailNewsDisplay
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.IsMailNewsDisplay


Gets and indication whether this encoding can be used for display by mail and news clients.
IsMailNewsSave
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.IsMailNewsSave


Gets an indication whether this encoding can be used for saving by mail and news clients.
WebName
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.WebName


Gets the name registered with the Internet Assigned Numbers Authority (IANA) for this encoding.
WindowsCodePage
(inherited from System.Text.Encoding)
Read-only

See base class member description: System.Text.Encoding.WindowsCodePage


Gets the Windows operating system code page that most closely corresponds to this encoding.
Public Methods
Equals
(inherited from System.Text.Encoding)
See base class member description: System.Text.Encoding.Equals


Determines whether the current instance and the specified Object represent the same type and value.
GetByteCount
(inherited from System.Text.Encoding)
Overloaded:
GetByteCount(char[] chars)

See base class member description: System.Text.Encoding.GetByteCount


Calculates the number of bytes required to encode a specified character array.
GetByteCount Overloaded:
GetByteCount(string chars)

Overridden:
Calculates the number of bytes required to store the results of encoding the characters from a specified String.
GetByteCount Overloaded:
GetByteCount(char[] chars, int index, int count)

Overridden:
Calculates the number of bytes required to store the results of encoding a set of characters from a specified Unicode character array.
GetBytes
(inherited from System.Text.Encoding)
Overloaded:
GetBytes(char[] chars)

See base class member description: System.Text.Encoding.GetBytes


Encodes a specified character array into a byte array.
GetBytes
(inherited from System.Text.Encoding)
Overloaded:
GetBytes(string s)

See base class member description: System.Text.Encoding.GetBytes


Encodes a specified String into an array of bytes.
GetBytes
(inherited from System.Text.Encoding)
Overloaded:
GetBytes(char[] chars, int index, int count)

See base class member description: System.Text.Encoding.GetBytes


Encodes a range of characters from a character array into a byte array.
GetBytes Overloaded:
GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)

Overridden:
Encodes a specified range of elements from a Unicode character array, and stores the results in a specified range of elements in a byte array.
GetBytes Overloaded:
GetBytes(string chars, int charIndex, int charCount, byte[] bytes, int byteIndex)

Overridden:
Encodes a specified range of characters from a String and stores the results in a specified range of elements in a byte array.
GetCharCount
(inherited from System.Text.Encoding)
Overloaded:
GetCharCount(byte[] bytes)

See base class member description: System.Text.Encoding.GetCharCount


Calculates the number of characters produced by decoding an array of bytes.
GetCharCount Overloaded:
GetCharCount(byte[] bytes, int index, int count)

Overridden:
Calculates the number of characters that would result from decoding a specified range of elements in a byte array.
GetChars
(inherited from System.Text.Encoding)
Overloaded:
GetChars(byte[] bytes)

See base class member description: System.Text.Encoding.GetChars


Decodes a byte array into an array of characters.
GetChars
(inherited from System.Text.Encoding)
Overloaded:
GetChars(byte[] bytes, int index, int count)

See base class member description: System.Text.Encoding.GetChars


Decodes a range of bytes from a byte array into a character array.
GetChars Overloaded:
GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)

Overridden:
Decodes a specified range of elements from a byte array, and stores the result into a specified range of elements in a Unicode character array.
GetDecoder
(inherited from System.Text.Encoding)
See base class member description: System.Text.Encoding.GetDecoder


Returns a Decoder for this encoding.
GetEncoder
(inherited from System.Text.Encoding)
See base class member description: System.Text.Encoding.GetEncoder


An Encoder for this encoding.
GetHashCode
(inherited from System.Text.Encoding)
See base class member description: System.Text.Encoding.GetHashCode


Returns the hash code for this instance.
GetMaxByteCount Overridden:
Calculates the maximum number of bytes required to encode a specified number of characters.
GetMaxCharCount Overridden:
Calculates the maximum number of characters that can result from decoding a specified number of bytes.
GetPreamble
(inherited from System.Text.Encoding)
See base class member description: System.Text.Encoding.GetPreamble


Returns a set of bytes used at the beginning of a stream to determine which encoding a file was created with. This can include the Unicode byte order mark.
GetString Overloaded:
GetString(byte[] bytes)

Overridden:
Converts a specified array of bytes to a String.
GetString Overloaded:
GetString(byte[] bytes, int byteIndex, int byteCount)

Overridden:
Converts a specified range of elements in an array of bytes to a String.
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.
Protected Methods
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:


System.Text.ASCIIEncoding Member Details

ctor #1
Summary
Initializes a new instance of the ASCIIEncoding class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public ASCIIEncoding();

Return to top


Property: BodyName (read-only)
Inherited
See base class member description: System.Text.Encoding.BodyName

Summary
Gets the name for this encoding that can be used with mail agent body tags.
C# Syntax:
public virtual string BodyName {get;}
Remarks
For example, if this encoding is equivalent to UTF8Encoding, this property returns "utf-8".

If the encoding cannot be used, the property value is the empty string ("").

Return to top


Property: CodePage (read-only)
Inherited
See base class member description: System.Text.Encoding.CodePage

Summary
When overridden in a derived class, gets the code page identifier of this encoding.
C# Syntax:
public virtual int CodePage {get;}
Remarks
This property must be implemented or overridden.
See also:
Encoding.#ctor

Return to top


Property: EncodingName (read-only)
Inherited
See base class member description: System.Text.Encoding.EncodingName

Summary
Gets the human-readable description of the encoding.
C# Syntax:
public virtual string EncodingName {get;}
Remarks
An example of an Encoding.EncodingName is Hebrew (DOS) for code page 862.

Return to top


Property: HeaderName (read-only)
Inherited
See base class member description: System.Text.Encoding.HeaderName

Summary
Gets the name for this encoding that can be used with mail agent header tags.
C# Syntax:
public virtual string HeaderName {get;}
Remarks
For example, if this encoding is equivalent to UTF8Encoding, this property returns "utf-8".

If the encoding cannot be used, the string is empty.

Return to top


Property: IsBrowserDisplay (read-only)
Inherited
See base class member description: System.Text.Encoding.IsBrowserDisplay

Summary
Gets an indication whether this encoding can be used for display by browser clients.
C# Syntax:
public virtual bool IsBrowserDisplay {get;}
Remarks
For example, this property returns true for code page 1252 (windows-1252), but false for code page 437 (IBM-437).

Return to top


Property: IsBrowserSave (read-only)
Inherited
See base class member description: System.Text.Encoding.IsBrowserSave

Summary
Gets an indication whether this encoding can be used for saving by browser clients.
C# Syntax:
public virtual bool IsBrowserSave {get;}
Remarks
For example, this property returns true for code page 1252 (windows-1252), but false for code page 437 (IBM-437).

Return to top


Property: IsMailNewsDisplay (read-only)
Inherited
See base class member description: System.Text.Encoding.IsMailNewsDisplay

Summary
Gets and indication whether this encoding can be used for display by mail and news clients.
C# Syntax:
public virtual bool IsMailNewsDisplay {get;}
Remarks
For example, this property returns true for code page 1252 (windows-1252), but false for code page 437 (IBM-437).

Return to top


Property: IsMailNewsSave (read-only)
Inherited
See base class member description: System.Text.Encoding.IsMailNewsSave

Summary
Gets an indication whether this encoding can be used for saving by mail and news clients.
C# Syntax:
public virtual bool IsMailNewsSave {get;}
Remarks
For example, this property returns true for code page 1252 (windows-1252), but false for code page 437 (IBM-437).

Return to top


Property: WebName (read-only)
Inherited
See base class member description: System.Text.Encoding.WebName

Summary
Gets the name registered with the Internet Assigned Numbers Authority (IANA) for this encoding.
C# Syntax:
public virtual string WebName {get;}

Return to top


Property: WindowsCodePage (read-only)
Inherited
See base class member description: System.Text.Encoding.WindowsCodePage

Summary
Gets the Windows operating system code page that most closely corresponds to this encoding.
C# Syntax:
public virtual int WindowsCodePage {get;}

Return to top


Method: Equals(
   object value
)
Inherited
See base class member description: System.Text.Encoding.Equals

Summary
Determines whether the current instance and the specified Object represent the same type and value.
C# Syntax:
public override bool Equals(
   object value
);
Parameters:

value

The Object to compare to the current instance.

Return Value:
true if value represents the same type and value as the current instance; otherwise, false.false if value is null or is not an instance of Encoding.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~ASCIIEncoding();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetByteCount(
   char[] chars
)
Inherited
See base class member description: System.Text.Encoding.GetByteCount

Summary
Calculates the number of bytes required to encode a specified character array.
C# Syntax:
public virtual int GetByteCount(
   char[] chars
);
Parameters:

chars

The character array to encode.

Return Value:
The number of bytes needed to encode chars.
Exceptions
Exception Type Condition
ArgumentNullException chars is null.
Remarks
Encoding.GetByteCount can be used to determine the exact the number of bytes that will be produced from encoding the given array of characters. An appropriately sized buffer for that conversion can then be allocated.

Alternatively, Encoding.GetMaxByteCount can be used to determine the maximum number of bytes that will be produced from converting a given number of characters. A buffer of that size can then be reused for multiple conversions.

The Encoding.GetByteCount method generally uses less memory, whereas the Encoding.GetMaxByteCount method generally executes faster.

Return to top


Overloaded Method: GetByteCount(
   string chars
)
Summary
Calculates the number of bytes required to store the results of encoding the characters from a specified String.
C# Syntax:
public override int GetByteCount(
   string chars
);
Parameters:

chars

The String to encode.

Return Value:
The number of bytes required to encode the characters in chars.
Exceptions
Exception Type Condition
ArgumentNullException chars is null.
Remarks
Use ASCIIEncoding.GetByteCount to calculate exactly, or ASCIIEncoding.GetMaxByteCount to calculate at most, the array size required by the ASCIIEncoding.GetBytes method to store encoded characters.

Return to top


Overloaded Method: GetByteCount(
   char[] chars,
   int index,
   int count
)
Summary
Calculates the number of bytes required to store the results of encoding a set of characters from a specified Unicode character array.
C# Syntax:
public override int GetByteCount(
   char[] chars,
   int index,
   int count
);
Parameters:

chars

The Unicode character array to encode.

index

The index of the first character in chars to encode.

count

The number of characters to encode.

Return Value:
The number of bytes necessary to encode the range in chars from index to index + count as an ASCIIEncoding.
Exceptions
Exception Type Condition
ArgumentNullException chars is null.
ArgumentOutOfRangeException index or count is less than zero.

-or-

index plus count is greater than the length of chars.

Remarks
Use ASCIIEncoding.GetByteCount to calculate exactly, or ASCIIEncoding.GetMaxByteCount to calculate at most, the array size required by the ASCIIEncoding.GetBytes method to store encoded characters.

Return to top


Overloaded Method: GetBytes(
   char[] chars
)
Inherited
See base class member description: System.Text.Encoding.GetBytes

Summary
Encodes a specified character array into a byte array.
C# Syntax:
public virtual byte[] GetBytes(
   char[] chars
);
Parameters:

chars

The character array to encode.

Return Value:
A byte array containing the encoded representation of chars.
Exceptions
Exception Type Condition
ArgumentNullException chars is null.
See also:
Encoding.GetByteCount | Encoding.GetMaxByteCount | Encoding.GetDecoder | Encoding.GetEncoder

Return to top


Overloaded Method: GetBytes(
   string s
)
Inherited
See base class member description: System.Text.Encoding.GetBytes

Summary
Encodes a specified String into an array of bytes.
C# Syntax:
public virtual byte[] GetBytes(
   string s
);
Parameters:

s

The String to encode.

Return Value:
A byte array containing the encoded representation of the specified string.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
Remarks
The Encoding.GetBytes method maintains no state between conversions. The method is intended for conversion of a complete block of characters in one operation.
See also:
Encoding.GetByteCount | Encoding.GetMaxByteCount | Encoding.GetDecoder | Encoding.GetEncoder

Return to top


Overloaded Method: GetBytes(
   char[] chars,
   int index,
   int count
)
Inherited
See base class member description: System.Text.Encoding.GetBytes

Summary
Encodes a range of characters from a character array into a byte array.
C# Syntax:
public virtual byte[] GetBytes(
   char[] chars,
   int index,
   int count
);
Parameters:

chars

The character array to encode.

index

The starting index of the character array to encode.

count

The number of characters to encode.

Return Value:
A byte array containing the encoded representation of the specified range of characters in chars.
Exceptions
Exception Type Condition
ArgumentNullException chars is null.
ArgumentOutOfRangeException The index and count parameters do not denote a valid range in chars.
See also:
Encoding.GetByteCount | Encoding.GetMaxByteCount | Encoding.GetDecoder | Encoding.GetEncoder

Return to top


Overloaded Method: GetBytes(
   char[] chars,
   int charIndex,
   int charCount,
   byte[] bytes,
   int byteIndex
)
Summary
Encodes a specified range of elements from a Unicode character array, and stores the results in a specified range of elements in a byte array.
C# Syntax:
public override int GetBytes(
   char[] chars,
   int charIndex,
   int charCount,
   byte[] bytes,
   int byteIndex
);
Parameters:

chars

The character array to encode.

charIndex

The index of the first character in chars to encode.

charCount

The number of characters to encode.

bytes

The byte array where the encoded results are stored.

byteIndex

The index of the first element in bytes where the encoded results are stored.

Return Value:
The number of bytes stored in bytes.
Exceptions
Exception Type Condition
ArgumentNullException chars or bytes is null.
ArgumentOutOfRangeException charIndex, charCount, or byteIndex is less than zero. -or-

charIndex plus charCount is greater than the length of chars.

-or-

byteIndex is greater than the length of bytes.

ArgumentException The length of bytes minus byteIndex is less than charCount.
Remarks
Any Unicode character greater than U+007F is translated to an ASCII question mark ('?').

Use ASCIIEncoding.GetByteCount to calculate exactly, or ASCIIEncoding.GetMaxByteCount to calculate at most, the array size required by the ASCIIEncoding.GetBytes method to store encoded characters.

See also:
ASCIIEncoding.GetByteCount | ASCIIEncoding.GetMaxByteCount

Return to top


Overloaded Method: GetBytes(
   string chars,
   int charIndex,
   int charCount,
   byte[] bytes,
   int byteIndex
)
Summary
Encodes a specified range of characters from a String and stores the results in a specified range of elements in a byte array.
C# Syntax:
public override int GetBytes(
   string chars,
   int charIndex,
   int charCount,
   byte[] bytes,
   int byteIndex
);
Parameters:

chars

The string of characters to encode.

charIndex

The index of the first character in chars to encode.

charCount

The number of characters to encode.

bytes

The byte array where the encoded results are stored.

byteIndex

The index of the first element in bytes where the encoded results are stored.

Return Value:
The number of bytes stored in bytes.
Exceptions
Exception Type Condition
ArgumentNullException chars or bytes is null.
ArgumentOutOfRangeException charIndex, charCount or byteIndex is less than zero.

-or-

charIndex plus charCount is greater than the length of chars.

-or-

byteIndex is greater than the length of bytes.

ArgumentException The length of bytes minus byteIndex is less than charCount.
Remarks
Use ASCIIEncoding.GetByteCount to calculate exactly, or ASCIIEncoding.GetMaxByteCount to calculate at most, the array size required by the ASCIIEncoding.GetBytes method to store encoded characters.
See also:
ASCIIEncoding.GetByteCount | ASCIIEncoding.GetMaxByteCount

Return to top


Overloaded Method: GetCharCount(
   byte[] bytes
)
Inherited
See base class member description: System.Text.Encoding.GetCharCount

Summary
Calculates the number of characters produced by decoding an array of bytes.
C# Syntax:
public virtual int GetCharCount(
   byte[] bytes
);
Parameters:

bytes

The byte array to decode.

Return Value:
The number of characters produced by decoding the specified byte array.
Exceptions
Exception Type Condition
ArgumentNullException bytes is null.
Remarks
The Encoding.GetCharCount method can be used to determine the exact the number of characters that will be produced from converting a given range of bytes. An appropriately sized buffer for that conversion can then be allocated.

Alternatively, the Encoding.GetMaxCharCount method can be used to determine the maximum number of characters that will produced for a given number of bytes. A buffer of that size can then be reused for multiple conversions.

The Encoding.GetCharCount method generally uses less memory, whereas the Encoding.GetMaxCharCount method generally executes faster.

Return to top


Overloaded Method: GetCharCount(
   byte[] bytes,
   int index,
   int count
)
Summary
Calculates the number of characters that would result from decoding a specified range of elements in a byte array.
C# Syntax:
public override int GetCharCount(
   byte[] bytes,
   int index,
   int count
);
Parameters:

bytes

The byte array to decode.

index

The index of the first byte in bytes to decode.

count

The number of bytes to decode.

Return Value:
The number of characters that would result from decoding the specified range of elements in bytes.
Exceptions
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.

Remarks
Use ASCIIEncoding.GetCharCount to calculate exactly, or ASCIIEncoding.GetMaxCharCount to calculate at most, the array size required by the ASCIIEncoding.GetChars method to store decoded bytes.

Return to top


Overloaded Method: GetChars(
   byte[] bytes
)
Inherited
See base class member description: System.Text.Encoding.GetChars

Summary
Decodes a byte array into an array of characters.
C# Syntax:
public virtual char[] GetChars(
   byte[] bytes
);
Parameters:

bytes

The byte array to decode.

Return Value:
A character array containing the decoded character representation from array bytes.
Exceptions
Exception Type Condition
ArgumentNullException bytes is null.
Remarks
Encoding.GetChars assumes that the byte array contains all the bytes necessary to produce whole characters. If your bytes might be in multiple byte arrays (that is, the bytes corresponding to a single character might be at the end of one byte array and the beginning of another), use the Decoder class, which maintains state between multiple calls.
See also:
Encoding.GetCharCount | Encoding.GetMaxCharCount

Return to top


Overloaded Method: GetChars(
   byte[] bytes,
   int index,
   int count
)
Inherited
See base class member description: System.Text.Encoding.GetChars

Summary
Decodes a range of bytes from a byte array into a character array.
C# Syntax:
public virtual char[] GetChars(
   byte[] bytes,
   int index,
   int count
);
Parameters:

bytes

The byte array to decode.

index

The starting index of the byte array to decode.

count

The number of bytes to decode.

Return Value:
A character array containing the decoded character representation from a range of array bytes.
Exceptions
Exception Type Condition
ArgumentNullException bytes is null.
ArgumentOutOfRangeException index and count do not denote a valid range in the byte array.
Remarks
Encoding.GetChars assumes that the byte array contains all the bytes necessary to produce whole characters. If your bytes might be in multiple byte arrays (that is, the bytes corresponding to a single character might be at the end of one byte array and the beginning of another), use the Decoder class, which maintains state between multiple calls.
See also:
Encoding.GetCharCount | Encoding.GetMaxCharCount

Return to top


Overloaded Method: GetChars(
   byte[] bytes,
   int byteIndex,
   int byteCount,
   char[] chars,
   int charIndex
)
Summary
Decodes a specified range of elements from a byte array, and stores the result into a specified range of elements in a Unicode character array.
C# Syntax:
public override int GetChars(
   byte[] bytes,
   int byteIndex,
   int byteCount,
   char[] chars,
   int charIndex
);
Parameters:

bytes

The byte array to decode.

byteIndex

The index of the first element in bytes to decode.

byteCount

The number of elements to decode.

chars

The character array where the decoded results are stored.

charIndex

The index of the first element in chars to store decoded results.

Return Value:
The number of characters stored in chars.
Exceptions
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.

ArgumentException The length of chars minus charIndex is less than byteCount.
Remarks
Any element of bytes to decode that is greater than hexadecimal 0x7F is translated to a Unicode question mark ('?').

Use ASCIIEncoding.GetCharCount to calculate exactly, or ASCIIEncoding.GetMaxCharCount to calculate at most, the array size required by the ASCIIEncoding.GetChars method to store decoded bytes.

See also:
ASCIIEncoding.GetCharCount | ASCIIEncoding.GetMaxCharCount | Encoding.GetChars

Return to top


Method: GetDecoder()
Inherited
See base class member description: System.Text.Encoding.GetDecoder

Summary
Returns a Decoder for this encoding.
C# Syntax:
public virtual Decoder GetDecoder();
Return Value:
Returns a Decoder for this encoding. The Decoder can be used to decode a sequence of bytes into characters.
Remarks
Contrary to the Encoding.GetChars methods, a Decoder can convert partial sequences of bytes into partial sequences of characters by maintaining the appropriate state between the conversions.

This default implementation returns a Decoder that forwards calls to the Encoding.GetCharCount and Encoding.GetChars methods to the corresponding methods of this encoding. Encodings that require state to be maintained between successive conversions can override this method and return an instance of an appropriate Decoder implementation.

See also:
Encoding.GetCharCount | Encoding.GetChars

Return to top


Method: GetEncoder()
Inherited
See base class member description: System.Text.Encoding.GetEncoder

Summary
An Encoder for this encoding.
C# Syntax:
public virtual Encoder GetEncoder();
Return Value:
An Encoder for this encoding. The Encoder can be used to encode a sequence of characters into bytes.
Remarks
Contrary to Encoding.GetBytes, an Encoder can convert partial sequences of characters into partial sequences of bytes by maintaining the appropriate state between the conversions.

This default implementation returns an Encoder that forwards calls to Encoding.GetByteCount and Encoding.GetBytes to the corresponding methods of this encoding. Encodings that require state to be maintained between successive conversions can override this method and return an instance of an appropriate Encoder implementation.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Text.Encoding.GetHashCode

Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Overridden Method: GetMaxByteCount(
   int charCount
)
Summary
Calculates the maximum number of bytes required to encode a specified number of characters.
C# Syntax:
public override int GetMaxByteCount(
   int charCount
);
Parameters:

charCount

The number of characters to encode.

Return Value:
The maximum number of bytes required to encode charCount number of characters.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException charCount is less than zero.
Remarks
Use this method to determine a maximum buffer size for byte arrays passed to ASCIIEncoding.GetBytes for the current encoding. Using this maximum buffer size helps ensure that buffer overflow exceptions do not occur.

Use ASCIIEncoding.GetByteCount to calculate exactly, or ASCIIEncoding.GetMaxByteCount to calculate at most, the array size required by the ASCIIEncoding.GetBytes method to store encoded characters.

See also:
ASCIIEncoding.GetBytes | Encoder.GetBytes

Return to top


Overridden Method: GetMaxCharCount(
   int byteCount
)
Summary
Calculates the maximum number of characters that can result from decoding a specified number of bytes.
C# Syntax:
public override int GetMaxCharCount(
   int byteCount
);
Parameters:

byteCount

The number of bytes to decode.

Return Value:
The maximum number of characters that can result from decoding byteCount number of bytes.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException byteCount is less than zero.
Remarks
Use this method to determine a maximum buffer size for character arrays passed to ASCIIEncoding.GetChars for the current encoding. Using this maximum buffer size helps ensure that buffer overflow exceptions do not occur.

Use ASCIIEncoding.GetCharCount to calculate exactly, or ASCIIEncoding.GetMaxCharCount to calculate at most, the array size required by the ASCIIEncoding.GetChars method to store decoded bytes.

See also:
ASCIIEncoding.GetChars | Decoder.GetChars

Return to top


Method: GetPreamble()
Inherited
See base class member description: System.Text.Encoding.GetPreamble

Summary
Returns a set of bytes used at the beginning of a stream to determine which encoding a file was created with. This can include the Unicode byte order mark.
C# Syntax:
public virtual byte[] GetPreamble();
Return Value:
The bytes at the beginning of a stream, which typically comprise the byte order mark.
Remarks
The preamble can be the Unicode byte order mark (U+FEFF written in the appropriate encoding) or any other type of identifying marks. This method can return an empty byte array.

Return to top


Overloaded Method: GetString(
   byte[] bytes
)
Summary
Converts a specified array of bytes to a String.
C# Syntax:
public override string GetString(
   byte[] bytes
);
Parameters:

bytes

A byte array.

Return Value:
A String whose characters are equivalent to the specified elements in bytes.
Exceptions
Exception Type Condition
ArgumentNullException bytes is null.
Remarks
Any element of the bytes array that is greater than hexadecimal 0x7F is translated to a Unicode question mark ('?').

Return to top


Overloaded Method: GetString(
   byte[] bytes,
   int byteIndex,
   int byteCount
)
Summary
Converts a specified range of elements in an array of bytes to a String.
C# Syntax:
public override string GetString(
   byte[] bytes,
   int byteIndex,
   int byteCount
);
Parameters:

bytes

A byte array.

byteIndex

The index of the first position in bytes to convert.

byteCount

The number of bytes to convert.

Return Value:
A String containing the values of the range in bytes from byteIndex to byteIndex + byteCount decoded as an ASCIIEncoding.
Exceptions
Exception Type Condition
ArgumentNullException bytes is null.
ArgumentOutOfRangeException byteIndex or byteCount is less than zero. -or-

byteIndex plus byteCount is greater than the length of bytes.

Remarks
Any element of the bytes array that is greater than hexadecimal 0x7F is translated to a Unicode question mark ('?').

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.