2

I am trying to print right filled arrow ► in C# this is I tried

 static void Main(string[] args) {
   Console.WriteLine((char)16);
 }

but it is showing the output as ? (question mark) I have gone through this question also but the it doesn't seem to work. Can you help me with correct ASCII code which shows the correct output?

Dmitry Bychenko
  • 165,109
  • 17
  • 150
  • 199
NetSurfer
  • 103
  • 8

3 Answers3

4

You can easily convert char to int and thus obtain its code:

  char arrow = '►'; // Copy + Paste from the question

  Console.Write($"{arrow} : {(int)arrow} : \\u{(int)arrow:X4}";);

Outcome:

  ► : 9658 : \u25BA

and that's why you can put

  char arrow = '\u25BA';
Dmitry Bychenko
  • 165,109
  • 17
  • 150
  • 199
4

Change the console output encoding before printing:

Console.OutputEncoding = Encoding.Unicode;
Console.WriteLine((char)9658);
// or just
//Console.WriteLine('►');
SᴇM
  • 6,769
  • 3
  • 25
  • 39
3

The black filled arrow is not included in the ascii charset. You need to use unicode.

In your example:

string myString = "\u25BA";
Console.WriteLine(myString);

You also need to be aware that the font you use can display the specific unicode character. As far as i know the default console font does not support it.

NoConnection
  • 689
  • 7
  • 21