如何更改 C# 控制台的输入编码方案?
csharpserver side programmingprogramming更新于 2025/5/25 8:07:17
要更改控制台的输入编码方案,请使用 Console.InputEncoding 属性。
示例
让我们看一个例子 −
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Text;
class Demo {
public static void Main (string[] args) {
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine("Background color changed = "+Console.BackgroundColor);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("
Foreground color changed = "+Console.ForegroundColor);
Console.InputEncoding = Encoding.ASCII;
Console.WriteLine("Input Encoding Scheme = "+Console.InputEncoding);
Console.CursorTop = 20;
Console.WriteLine("
CursorTop = "+Console.CursorTop);
}
}
输出
这将产生以下输出 −


