Console.WriteLine as hexadecimal

Kevin Driedger picture Kevin Driedger · Aug 27, 2009 · Viewed 87.9k times · Source

The following code prints out 10. How can I make it print out a?

int i = 10;
Console.WriteLine("{0}", i);

Answer

jscharf picture jscharf · Aug 27, 2009
Console.WriteLine ("Hex: {0:X}", nNum);

The X formatter outputs uppercase hex chars. Use a lowercase x for lowercase hex chars.