[英]Why “write” function doesn't work at first time?
結果寫入功能不適用於“ 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(" ╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝");
}
}
它正在工作,但是您看不到它。
嘗試
Console.Write(" ╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗\n");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Blue;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.