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

CsharpServer Side ProgrammingProgramming

Use the Console.OutputEncoding property in C# to change the Output Encoding Scheme in C#.

Example

Let us see an example −

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Demo {
   public static void Main (string[] args) {
      Console.BackgroundColor = ConsoleColor. Black;
      Console.WriteLine("Background color changed = "+Console.BackgroundColor);
      Console.ForegroundColor = ConsoleColor.White;
      Console.WriteLine("\nForeground color changed = "+Console.ForegroundColor);
      Console.InputEncoding = Encoding.ASCII;
      Console.WriteLine("Input Encoding Scheme = "+Console.InputEncoding);
      Console.OutputEncoding = Encoding.ASCII;
      Console.WriteLine("Output Encoding Scheme = "+Console.OutputEncoding);
   }
}

Output

This will produce the following output −

raja
Published on 14-Nov-2019 10:59:46
Advertisements