Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Cách thay đổi Input Encoding Scheme của Console C#

Để thay đổi bộ mã hóa đầu vào của Console, sử dụng thuộc tính Console.InputEncoding.

Ví dụ

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("Màu nền đã thay đổi = " + Console.BackgroundColor); 
        Console.ForegroundColor = ConsoleColor.Yellow; 
        Console.WriteLine("\nMàu chữ đã thay đổi = " + Console.ForegroundColor); 
        Console.InputEncoding = Encoding.ASCII; 
        Console.WriteLine("Chuỗi mã hóa đầu vào = " + Console.InputEncoding); 
        Console.CursorTop = 20; 
        Console.WriteLine("\nCursorTop = " + Console.CursorTop); 
    } 
}

Kết quả

Cách thay đổi Input Encoding Scheme của Console C#