System.Text.Encoding.ASCII Property

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

Syntax

public static Encoding ASCII { get; }

Value

Documentation for this section has not yet been entered.

Remarks

ASCII characters are limited to the lowest 128 Unicode characters, from U+0000 to U+007F.

When selecting the ASCII encoding for your applications, consider the following:

  • The ASCII encoding is usually appropriate for protocols that require ASCII.

  • If your application requires 8-bit encoding (which is sometimes incorrectly referred to as "ASCII"), the UTF-8 encoding is recommended over the ASCII encoding. For the characters 0-7F, the results are identical, but use of UTF-8 avoids data loss by allowing representation of all Unicode characters that are representable. Note that the ASCII encoding has an 8th bit ambiguity that can allow malicious use, but the UTF-8 encoding removes ambiguity about the 8th bit.

  • Prior to the .NET Framework version 2.0, the .NET Framework allowed spoofing by ignoring the 8th bit. Beginning with the .NET Framework 2.0, non-ASCII code points fall back during decoding.

The System.Text.ASCIIEncoding object that is returned by this property might not have the appropriate behavior for your application. It uses replacement fallback to replace each string that it cannot encode and each byte that it cannot decode with a question mark ("?") character. Instead, you can call the Encoding.GetEncoding(string, EncoderFallback, DecoderFallback) method to instantiate an System.Text.ASCIIEncoding object whose fallback is either an System.Text.EncoderFallbackException or a System.Text.DecoderFallbackException, as the following example illustrates.

code reference: System.Text.Encoding.ASCII#1

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0