结果写入功能对“8”不起作用,但分别写入7,6,5,....当我跟踪代码时,我找不到任何错误...(代码必须用数字绘制国际象棋棋盘)
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(" a b c d e f g h");
Console.BackgroundColor = ConsoleColor.Blue;
Console.Write(" ╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗\n");
Console.ForegroundColor = ConsoleColor.Blue;
for (int i = 7; i > -1;i--)
{
Console.Write((i + 1).ToString());//Problem is here
for (int j=0;j<8;j++)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Blue;
Console.Write("║");
if(i%2!=0)
{
if(j%2==0)
{
Console.BackgroundColor = ConsoleColor.White;
}
else
{
Console.BackgroundColor = ConsoleColor.Black;
}
}
else
{
if (j % 2 == 0)
{
Console.BackgroundColor = ConsoleColor.Black;
}
else
{
Console.BackgroundColor = ConsoleColor.White;
}
}
Console.Write(" "+ch[i,j].ToString()+" ");
}
Console.BackgroundColor = ConsoleColor.Blue;
Console.Write("║\n");
if(i!=0)
{
Console.WriteLine(" ╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣");
}
else
{
Console.WriteLine(" ╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝");
}
}
答案 0 :(得分:2)
它正在工作,但你看不到它。
尝试
Console.Write(" ╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗\n");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Blue;