官术网_书友最值得收藏!

Color

Console background and/or foreground color can be changed using setter and getter properties that accept the value of the ConsoleColor enum. To set it to the default color, there is a Reset method. Let's demonstrate all color combinations using the following code:

private static (int, int) DisplayColorMenu(ConsoleColor[] colors) 
{ 
var count = 0; 
 
foreach (var color in colors) 
    { 
        WriteLine($"{count}{color}"); 
        count += 1; 
    } 
WriteLine($"{count + 1} Reset"); 
WriteLine($"{count + 2} Exit"); 
 
Write("Choose Foreground color:"); 
var foreground = Convert.ToInt32(ReadLine()); 
Write("Choose Background color:"); 
var background = Convert.ToInt32(ReadLine()); 
 
return new ValueTuple<int, int>(background, foreground); 
} 

The preceding code is one snippet from the complete source code that is available on the GitHub repository. The complete code will provide the following output:

主站蜘蛛池模板: 高台县| 山阴县| 华池县| 邯郸县| 济南市| 喀喇沁旗| 西吉县| 屏东县| 乳源| 阿拉善右旗| 阿尔山市| 孝义市| 句容市| 嘉兴市| 都昌县| 眉山市| 图木舒克市| 台山市| 库车县| 梨树县| 白山市| 体育| 大同市| 井冈山市| 加查县| 南川市| 沭阳县| 观塘区| 得荣县| 荆门市| 大兴区| 雷波县| 乌兰察布市| 天祝| 西林县| 苏尼特右旗| 昌吉市| 永兴县| 赣州市| 新建县| 清涧县|