How to change the Input Encoding Scheme of the C# Console?

CsharpServer Side ProgrammingProgramming

To change the Input Encoding Scheme of the Console, use the Console.InputEncoding property.


Let us see an example −

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("\nForeground color changed = "+Console.ForegroundColor);
      Console.InputEncoding = Encoding.ASCII;
      Console.WriteLine("Input Encoding Scheme = "+Console.InputEncoding);
      Console.CursorTop = 20;
      Console.WriteLine("\nCursorTop = "+Console.CursorTop);


This will produce the following output −

Updated on 14-Nov-2019 06:27:24