Console.WriteLine as hexadecimal

Console.WriteLine ("Hex: {0:X}", nNum);

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


i.ToString("x");


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

Outputs hex with a size specifier.

you can also use string interpolation

int i=10;
Console.WriteLine($"{i:X4}");