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

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:

主站蜘蛛池模板: 盱眙县| 彰化市| 冕宁县| 老河口市| 塔河县| 蛟河市| 宿松县| 大余县| 名山县| 吴江市| 安乡县| 镇巴县| 济源市| 六安市| 滁州市| 潞西市| 紫金县| 湖州市| 乐都县| 罗定市| 克山县| 纳雍县| 砀山县| 久治县| 奉化市| 西贡区| 邵武市| 乐安县| 肃宁县| 临桂县| 尼勒克县| 济源市| 都江堰市| 汶上县| 咸宁市| 石河子市| 冷水江市| 明水县| 石城县| 巴青县| 永安市|