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

推薦閱讀
- 軟件項目管理(第2版)
- Linux核心技術從小白到大牛
- Mastering PHP Design Patterns
- OpenNI Cookbook
- The DevOps 2.4 Toolkit
- Big Data Analytics
- 小學生C++創意編程(視頻教學版)
- Learning Salesforce Einstein
- UVM實戰
- 編程與類型系統
- ServiceNow:Building Powerful Workflows
- Nagios Core Administration Cookbook(Second Edition)
- C陷阱與缺陷
- Moodle 3 Administration(Third Edition)
- Python應用開發技術