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

  • Learn C# in 7 days
  • Gaurav Aroraa
  • 118字
  • 2021-07-08 09:51:23

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:

主站蜘蛛池模板: 普宁市| 库尔勒市| 拜城县| 金门县| 永丰县| 子长县| 长宁区| 绵阳市| 抚远县| 永川市| 贵德县| 思南县| 鄂托克旗| 桂阳县| 太白县| 保德县| 玉溪市| 汾阳市| 南汇区| 荣成市| 万山特区| 五原县| 静海县| 化隆| 长顺县| 章丘市| 大连市| 马公市| 两当县| 丘北县| 萝北县| 顺义区| 博白县| 卢湾区| 井研县| 南宁市| 柏乡县| 德阳市| 富裕县| 稻城县| 区。|