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

推薦閱讀
- Android Wearable Programming
- Python入門很簡單
- 基于Java技術的Web應用開發
- Android程序設計基礎
- .NET 3.5編程
- UVM實戰
- Mastering React
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- Android傳感器開發與智能設備案例實戰
- Machine Learning for Developers
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- 劍指大數據:企業級電商數據倉庫項目實戰(精華版)
- R for Data Science Cookbook
- Python Geospatial Analysis Cookbook
- 精通Django 3 Web開發