C# 如何改变控制台输出字体颜色

2025-03-07 00:41:52
推荐回答(2个)
回答1:

private static string Str = @"<>□□□□☆◎□□▲□□□☆□□□☆□□卐□□◎□卐□▲□□";

        static void Main(string[] args)
        {

            foreach(char c in Str)
            {
                if (c == '☆')
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.White;
                }
                Console.Write(c);

            }
            Console.WriteLine();

            Console.ReadKey();

回答2:

using System;

class Program
{
static void WriteString(String s)
{
    var orginColor = Console.ForegroundColor;
    for(int i=0;i    {
if(s[i].Equals('☆'))
{
Console.ForegroundColor = ConsoleColor.Red;
}
else Console.ForegroundColor = orginColor;
Console.Write(s[i]);
    }
    Console.WriteLine();
}
static void Main()
{
WriteString("<>□□□□☆◎□□▲□□□☆□□□☆□□卐□□◎□

卐□▲□□");
}
}