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
  • 180,369
  • 20
  • 160
  • 215
NetSurfer
  • 103
  • 1
  • 9

4 Answers4

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
  • 180,369
  • 20
  • 160
  • 215
4

Change the console output encoding before printing:

Console.OutputEncoding = Encoding.Unicode;
Console.WriteLine((char)9658);
// or just
//Console.WriteLine('►');
SᴇM
  • 7,024
  • 3
  • 24
  • 41
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
  • 765
  • 7
  • 23
0

For .NET 5+ the following code is relevant:

Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("↑▲");
Stepagrus
  • 1,189
  • 1
  • 12
  • 19