【发布时间】:2018-02-26 21:40:17
【问题描述】:
我正在尝试在控制台应用程序中获得这种颜色结果:
但这是我现在的结果:
这是我的代码:
static void Main(string[] args)
{
string[] str = new string[]
{
" ________ __ ",
"/ | / | ",
"$$$$$$$$/______ _______ _$$ |_ ",
" $$ | / \\ / |/ $$ | ",
" $$ |/$$$$$$ |/$$$$$$$/ $$$$$$/ ",
" $$ |$$ $$ |$$ \\ $$ | __ ",
" $$ |$$$$$$$$/ $$$$$$ | $$ |/ | ",
" $$ |$$ |/ $$/ $$ $$/ ",
" $$/ $$$$$$$/ $$$$$$$/ $$$$/ "
};
Console.ForegroundColor = ConsoleColor.Green;
for (int i = 0; i < str.Length; i++)
{
for (int j = 0; j < str[i].Length; j++)
{
if (i >= 4 && i < 7 && j > 3 && j < 5)
{
Console.ForegroundColor = ConsoleColor.Blue;
}
Console.Write(str[i][j]);
}
Console.WriteLine();
}
Console.ResetColor();
}
如何在控制台应用程序中每行获得多种颜色?
【问题讨论】:
-
是的,这是可能的,但我不认为你可以在这样的循环中做到这一点。您可以使用
Console.ForegroundColor、Console.Write(可能还有Console.SetCursorPosition)的组合来用不同的颜色书写您想要的字符。