public static System.ConsoleColor FromColor(System.Drawing.Color c){
int index = (c.R > 128 | c.G > 128 | c.B > 128) ? 8 : 0; // Bright bit
index |= (c.R > 64) ? 4 : 0; // Red bit
index |= (c.G > 64) ? 2 : 0; // Green bit
index |= (c.B > 64) ? 1 : 0; // Blue bit
return (System.ConsoleColor)index;
}
static void Main(){
Console.WriteLine("Enter the text you want to color ");
var color = Console.ReadLine().Trim();//Вводим #AA0000 по итогу будет RED
Console.BackgroundColor = FromColor(ColorTranslator.FromHtml(color));
Console.Clear();
Console.WriteLine("HELLO");
Console.ReadKey();
}
Console.WriteLine("Enter the text you want to color ");
var color = Console.ReadLine().Trim();//Вводим Red
ConsoleColor col;
if (ConsoleColor.TryParse(color, out col)){
Console.BackgroundColor= col;
Console.Clear();
Console.WriteLine("Hello");
}
Console.ReadKey();
return;