Export (0) Print
Expand All

ASCIIEncoding Constructor

Initializes a new instance of the ASCIIEncoding class.

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

public ASCIIEncoding()

Caution noteCaution

The ASCIIEncoding class does not provide error detection. For security reasons, you should use the UTF8Encoding, UnicodeEncoding, or UTF32Encoding class and enable error detection.

If you choose to use ASCII encoding, this constructor may not provide the appropriate fallback behavior for your application. It uses the EncoderReplacementFallback and DecoderReplacementFallback classes to replace every character outside the range of U+0000 through U+007F with a question mark (?). Instead, you can call the Encoding.GetEncoding(Int32, EncoderFallback, DecoderFallback) or Encoding.GetEncoding(String, EncoderFallback, DecoderFallback) method and pass it EncoderExceptionFallback and DecoderExceptionFallback objects to use exception fallback.

NoteNote

ASCIIEncoding supports only the Unicode character values between U+0000 and U+007F. Therefore, UTF8Encoding, UnicodeEncoding, and UTF32Encoding are better suited for globalized applications.

The following example demonstrates how to create a new ASCIIEncoding instance and display the name of the encoding.

using System;
using System.Text;

class ASCIIEncodingExample {
    public static void Main() {
        ASCIIEncoding ascii = new ASCIIEncoding();
        String encodingName = ascii.EncodingName;
        Console.WriteLine("Encoding name: " + encodingName);
    }
}

.NET Framework

Supported in: 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