Console::OutputEncoding Property

 

Gets or sets the encoding the console uses to write output.

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

public:
property Encoding^ OutputEncoding {
	static Encoding^ get();
	static void set(Encoding^ value);
}

Property Value

Type: System.Text::Encoding^

The encoding used to write console output.

Exception Condition
ArgumentNullException

The property value in a set operation is null.

IOException

An error occurred during the execution of this operation.

SecurityException

Your application does not have permission to perform this operation.

The console uses the output encoding to translate characters written by an application into corresponding console display characters. The default code page that the console uses is determined by the system locale.

Starting with the .NET Framework 4, a property get operation may return a cached value instead of the console's current output encoding. This can occur if the value of the OutputEncoding property is modified by some means other than an assignment to the OutputEncoding property, such as calling the Windows SetConsoleOutputCP function.

Notes to Callers:

Of the Unicode encodings, the Console class supports UTF-8 encoding with the UTF8Encoding class and, starting with the .NET Framework 4.5, it supports UTF-16 encoding with the UnicodeEncoding class. UTF-32 encoding with the UTF32Encoding class is not supported. Attempting to set the output encoding to UTF-32 throws an IOException.

Note that successfully displaying Unicode characters to the console requires the following:

  • The console must use a TrueType font, such as Lucida Console or Consolas, to display characters.

  • A font used by the console must define the particular glyph or glyphs to be displayed. The console can take advantage of font linking to display glyphs from linked fonts if the base font does not contain a definition for that glyph.

For more information about support for Unicode encoding by the console, see the "Unicode Support for the Console" section in the Console class.

UIPermission

for reading and writing to top-level windows and subwindows. Associated enumeration: UIPermissionWindow::SafeTopLevelWindows

.NET Framework
Available since 2.0
Return to top
Show: