Reputation: 235
The ConsoleColor.Red code will give you the colour red right. The code (ConsoleColor)3746 will give you another colour. But what is this number (rgb,hex) and how do I convert into an rgb value of vice versa.
Upvotes: 2
Views: 2126
Reputation: 27419
First, let's see the colors
var colors = Enum.GetValues(typeof(ConsoleColor)).Cast<ConsoleColor>();
foreach (var color in colors)
{
Console.BackgroundColor = color;
Console.WriteLine(color);
}
The world of console colors is 4 bit: one each for red, green and blue, and 1 for intensity, which doubles the saturation of the given color (except for Gray / White). This gives is 15 possible distinct colors. The corresponding hex would be 0, 80 and FF for each of red, green and blue:
Name R G B
-------------------------
Black 00 00 00
DarkBlue 00 00 80
DarkGreen 00 80 00
DarkCyan 00 80 80
DarkRed 80 00 00
DarkMagenta 80 00 80
DarkYellow 80 80 00
DarkGray 80 80 80
Blue 00 00 FF
Green 00 FF 00
Cyan 00 FF FF
Red FF 00 00
Magenta FF 00 FF
Yellow FF FF 00
Gray C0 C0 C0
White FF FF FF
Note that 'Gray' is the odd one out. The reason for this is that 4 bits actually allows 16 colors, but only 15 can be uniquely encoded for in the off-on-on+intensity scheme.
Upvotes: 9