【发布时间】:2015-03-09 19:33:48
【问题描述】:
我目前正在尝试更改数组的背景颜色,特别是在本例中为 grid[0, 0]。我已经搜索了一段时间,似乎无法提出任何建议。这可能是一个相当简单的问题,或者我需要休息一下!
Console.BackgroundColor(grid[0,0]) = ConsoleColor.Cyan;
我正在尝试使背景颜色为青色。变量是一个字符串,包含一个空格。
提前干杯。
完整来源:
static void Main(string[] args)
{
Console.CursorSize = 100;
int row, col;
string[,] grid = new string[10, 10];
for (col = 0; col < 10; col++)
{
for (row = 0; row < 10; row++)
{
grid[col, row] = " ";
}
}
for (col = 0; col < 10; col++)
{
for (row = 0; row < 10; row++)
{
Console.Write(grid[col, row]);
}
Console.Write("\n");
}
Console.BackgroundColor(grid[0,0]) = ConsoleColor.Cyan;
Console.ReadKey();
}
【问题讨论】:
-
什么是
grid?Console.BackgroundColor是一个属性,您正试图将其用作方法。也许你只想要Console.BackgroundColor = ConsoleColor.Cyan;,但我不知道grid在这里如何应用。 -
你想设置什么?数组中文本的背景颜色?
-
“数组的背景颜色”不是一个有意义的短语(您想要该数据库的颜色是什么?)..您到底想做什么?
-
我相信他想改变控制台缓冲区中单个单元格的颜色。