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

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

主站蜘蛛池模板: 富平县| 望谟县| 石阡县| 水富县| 黄陵县| 宜章县| 洞口县| 长岛县| 连云港市| 德清县| 清苑县| 永仁县| 余江县| 图木舒克市| 安龙县| 白银市| 长沙县| 巴林左旗| 长宁县| 波密县| 禄劝| 西乌珠穆沁旗| 五华县| 玉溪市| 绥中县| 沾化县| 衡阳县| 汤阴县| 临颍县| 无为县| 中西区| 鄯善县| 应用必备| 临海市| 哈尔滨市| 贵溪市| 循化| 台东市| 乌鲁木齐县| 沙河市| 巴南区|