c# use ConsoleColor as int

Viewed 1473

Is there some way I can use ConsoleColors as the Ints that they are? Like

Console.ForeGroundColor = 10; //ConsoleColor.Green has the Value of 10

but i can only use

Console.ForeGroundColor = ConsoleColor.Green; //when hovering over "Green" Visual Studio even shows me that Green is 10

I managed to find these Color-Ints in the registry (HKEY_CURRENT_USER/Console) where the Ints have hexCodes of the colors but no where the name (and i was able to change the value of Green to Orange and back to default but that doesn't matter). So why won't C# or Visual Studio let me use the Ints? Or am I doing something Wrong?

Please try to explain it without using refering to enums. I know, these colornames are enums but i just don't understand enum-conversion yet

2 Answers

I use Vs 2017: I wrote

Console.ForegroundColor = (ConsoleColor)10;
Console.ForegroundColor = (ConsoleColor)12;

and worked !

Related