Export (0) Print
Expand All

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 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 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 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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft