Console.InputEncoding 属性

定义

获取或设置控制台用于读取输入的编码。

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Text.Encoding InputEncoding { get; set; }
C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Text.Encoding InputEncoding { get; set; }
C#
public static System.Text.Encoding InputEncoding { get; set; }

属性值

Encoding

用于读取控制台输入的编码。

属性

例外

集运算中的属性值为 null

执行此操作期间出错。

你的应用程序没有执行此操作的权限。

注解

控制台使用输入编码将键盘输入转换为相应的字符。 输入编码包含将 256 个键盘字符代码映射到单个字符的代码页。 不同的代码页包含不同的特殊字符,通常会对一种语言或一组语言进行自定义。

从 .NET Framework 4 开始,属性获取操作可能会返回缓存的值,而不是控制台的当前输入编码。 如果通过某种方式(而不是对 属性的赋值)修改属性的值(例如调用 Windows 函数或从 PowerShell 脚本使用 命令)时 InputEncoding InputEncoding ,可能会 SetConsoleCP chcp 发生这种情况。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

另请参阅