如何更改 C# 控制檯中的文字前景色?


要在 C# 中更改文字的前景色,請使用 Console.ForegroundColor 屬性。

示例

我們來看一個示例 −

using System;
class Demo {
   public static void Main (string[] args) {
      Console.BackgroundColor = ConsoleColor.Blue;
      Console.WriteLine("Background color changed = "+Console.BackgroundColor);
      Console.ForegroundColor = ConsoleColor.Yellow;
      Console.WriteLine("
Foreground color changed = "+Console.ForegroundColor);    } }

輸出

這將產生以下輸出 −

更新於: 2019 年 11 月 13 日

9K+ 瀏覽

開啟您的職業生涯之路生涯

完成本課程獲得認證

開始
廣告
© . All rights reserved.