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

  • 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:

主站蜘蛛池模板: 靖远县| 阜新| 平阴县| 安远县| 松溪县| 林周县| 池州市| 绥阳县| 旅游| 荃湾区| 罗山县| 沁水县| 定州市| 江西省| 武城县| 雷波县| 辽宁省| 乃东县| 神木县| 锡林浩特市| 个旧市| 万荣县| 瑞金市| 永泰县| 汝阳县| 崇州市| 吴堡县| 炎陵县| 新宁县| 临澧县| 葫芦岛市| 深水埗区| 博客| 苍梧县| 扬州市| 昌平区| 信阳市| 和龙市| 南通市| 斗六市| 大埔县|