Udostępnij za pośrednictwem


Fallback Encoding Application Sample

This sample demonstrates features of the Encoding class, including a fallback mechanism, new to the .NET Framework version 2.0, that allows you to specify its behavior when it encounters problems during the encoding or decoding process.

For information about using the samples, see the following topics:

To build the sample using the Command Prompt

  1. Open the Command Prompt window and navigate to one of the language-specific subdirectories under the EncodingApp directory. For information about required settings and the SDK Command Prompt, see How to: Set Sample Settings.

  2. Type msbuild EncodingAppCS.sln or msbuild EncodingAppVB.sln, depending on your choice of programming language.

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to one of the language-specific subdirectories under the EncodingApp directory.

  2. Double-click the EncodingAppCS.sln or EncodingAppVB.sln file, depending on your choice of programming language, to open the file in Visual Studio.

  3. From the Build menu, select Build Solution.

The application will be built in the default \bin or \bin\Debug subdirectory.

To run the sample

  1. In Windows Explorer or in the Command Prompt window, navigate to the directory that contains the new executable.

  2. Double-click the icon for the EncodingApplication file in Windows Explorer, or type EncodingApplication.exe in the Command Prompt window to open the application.

Remarks

The sample builds a Windows Forms application. You can launch and run it like any Windows application.

This sample highlights the EncoderFallback and DecoderFallback classes and their derived types, which expose static methods and fields that allow developers to specify the fallback behavior of an Encoding in cases where it cannot encode or decode a character or byte.

The EncodingApplication executable file displays the encoding and decoding of characters and bytes in any encoding format supported by the .NET Framework. You can view decimal or hexadecimal representations of any character in the Unicode standard. For more information about the Unicode Standard, see the specification at www.unicode.org.

The DecoderExceptionFallback and DecoderReplacementFallback types are derived from the DecoderFallback class, and the EncoderExceptionFallback and EncoderReplacementFallback types are derived from the EncoderFallback class. Each of these types is associated with a corresponding class derived from DecoderFallbackBuffer or EncoderFallbackBuffer. The encoding fallback mechanism depends on the functionality exposed by these closely related classes.

See Also

Concepts

String Indexing

Unicode in the .NET Framework

Reference

DecoderFallback class

DecoderExceptionFallback class

DecoderReplacementFallback class

EncoderExceptionFallback class

EncoderReplacementFallback class

EncoderFallback class

Encoding class

System.Text namespace