ASCII Property

Encoding.ASCII Property


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

Namespace:   System.Text
Assembly:  mscorlib (in mscorlib.dll)

static member ASCII : Encoding with get

Property Value

Type: System.Text.Encoding

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

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

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

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

  • If you 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 ASCIIEncoding object that is returned by this property might not have the appropriate behavior for your app. 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 GetEncoding(String, EncoderFallback, DecoderFallback) method to instantiate an ASCIIEncoding object whose fallback is either an EncoderFallbackException or a DecoderFallbackException, as the following example illustrates.

No code example is currently available or this language may not be supported.

The following example demonstrates the effect of the ASCII encoding on characters that are outside the ASCII range.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft