Encoding.Unicode is UTF-16, which uses 2 bytes to encode all characters. ASCII characters (English characters) are the same in UTF-8 (single bytes, same values), so it is possible that this works.
I assume that the Windows Command Shell does not fully support Unicode. It's funny that the Powershell 2 GUI supports UTF-16 (as far as I know), but the program throws an exception there.
The following code works, which shows that the Console object can redirect its output and support Encoding.Unicode:
FileStream testStream = File.Create("test.txt"); TextWriter writer = new StreamWriter(testStream, Encoding.Unicode); Console.SetOut(writer); Console.WriteLine("Hello World: \u263B");
user10789
source share