Editar

Compartir vía


Console.OutputEncoding Property

Definition

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

public:
 static property System::Text::Encoding ^ OutputEncoding { System::Text::Encoding ^ get(); void set(System::Text::Encoding ^ value); };
public static System.Text.Encoding OutputEncoding { get; set; }
public static System.Text.Encoding OutputEncoding { get; [System.Runtime.Versioning.UnsupportedOSPlatform("android")] [System.Runtime.Versioning.UnsupportedOSPlatform("ios")] [System.Runtime.Versioning.UnsupportedOSPlatform("tvos")] set; }
static member OutputEncoding : System.Text.Encoding with get, set
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<set: System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member OutputEncoding : System.Text.Encoding with get, set
Public Shared Property OutputEncoding As Encoding

Property Value

The encoding used to write console output.

Attributes

Exceptions

The property value in a set operation is null.

An error occurred during the execution of this operation.

Your application does not have permission to perform this operation.

Remarks

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.

Applies to