0

I have int values stored in a list, that I want to output as unicode characters, like this:

 //A List<int> named Kanji exists and has values
    Console.OutputEncoding = Encoding.Unicode;
    int i = 0;
    while (i < Kanji.Count)
    {
        Console.WriteLine((char)Kanji[i]);
        i++;
    }

But this only returns ? characters. What should I do? The int values themselves are fine, I tested them.

2
  • If it only returns ? then you need to have Japanese language packs installed or active in your solution - something to do with the unicode character not displaying correctly Commented Nov 1, 2016 at 16:48
  • 1
    This actually has very little to do with C#; google around on how to make the console work correctly with unicode - it doesn't support it "out of the box", and your application has very little control over most of the reasons why it wouldn't work. Commented Nov 1, 2016 at 16:57

1 Answer 1

1

The console is probably not using a Unicode or Japanese encoding, and/or the font used does not contain the required character glyphs.

Have a look at Console.OutputEncoding for more information, and the Unicode Support for the Console section.

Sign up to request clarification or add additional context in comments.

4 Comments

His code shows Console.OutputEncoding = Encoding.Unicode;, so I assume the "or" part of your comment is the only relevant part: "or the font used does not contain the required character glyphs".
The page I link to lists all the caveats, such as supporting UTF16 (which Encoding.Unicode is) only from .NET 4.5 onward, and that the console must use a TrueType font with the required glyphs... so if .NET 4.0 or earlier is being used as target framework, only UTF8 would be supported.
"In general, the console reads input and writes output by using the current console code page, which the system locale defines by default. A code page can handle only a subset of available Unicode characters, so if you try to display characters that are not mapped by a particular code page, the console won't be able to display all characters or represent them accurately"
Thank you Lucero, stuartd and Luaan, the problem was with the console itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.