这是我的二维表代码。
我想做的是把我的输入放在正确的位置——但正如你所看到的,我的表输出并不是应该的。列与行重叠。我的问题是:如何才能将列稍微向右放置一点。此外,我如何才能在正确的位置输入?
感谢您提供一些提示和帮助。
string[,] clubs = new string[20, 30];
clubs[1, 0] = " ADO";
clubs[2, 0] = " Ajax";
clubs[3, 0] = " AZ";
clubs[4, 0] = " FC-GR";
clubs[5, 0] = " FC-TW";
clubs[6, 0] = " FC-U";
clubs[7, 0] = " FEY";
clubs[8, 0] = " HER";
clubs[9, 0] = " NAC";
clubs[10, 0] = " NEC";
clubs[11, 0] = " PSV";
clubs[12, 0] = " RKC";
clubs[13, 0] = " ROD";
clubs[14, 0] = " SC";
clubs[15, 0] = " SPA";
clubs[16, 0] = " VIT";
clubs[17, 0] = " VVV";
clubs[18, 0] = " WIL";
clubs[0, 1] = "Ado Den haag";
clubs[0, 2] = "Ajax";
clubs[0, 3] = "AZ";
clubs[0, 4] = "FC Groningen";
clubs[0, 5] = "FC Twente";
clubs[0, 6] = "FC Utrecht";
clubs[0, 7] = "Feyenoord";
clubs[0, 8] = "Hercules Almelo";
clubs[0, 9] = "NAC Breda";
clubs[0, 10] = "NEC";
clubs[0, 11] = "PSV";
clubs[0, 12] = "RKC Waalwijk";
clubs[0, 13] = "Roda JC";
clubs[0, 14] = "SC Heerenveen";
clubs[0, 15] = "Sparta Rotterdam";
clubs[0, 16] = "Vitesse";
clubs[0, 17] = "VVV-Venlo";
clubs[0, 18] = "Willem II";
int rows = 15;
int colums = 15;
int x = 0;
int y = 0;
string str;
int thuisteam;
int uitteam;
Console.WriteLine("Selecteer de thuisteam op een nummer");
for (int i = 1; i < colums; i++)
{
Console.WriteLine(clubs[i, 0] + " " + i);
}
str = Console.ReadLine();
thuisteam = Int32.Parse(str);
Console.WriteLine("Selecteer de uitteam in onderstaande nummer");
for (int i = 1; i < rows; i++)
{
Console.WriteLine(clubs[0, i] + " " + i);
}
str = Console.ReadLine();
uitteam = Int32.Parse(str);
Console.WriteLine("Schrijf de score of datum van je wedstrijd op");
str = Console.ReadLine();
clubs[thuisteam, uitteam] = str;
Console.WriteLine();
for (; y < rows; y++)
{
for (; x < colums; x++)
{
Console.Write(clubs[x, y] + " ");
if (x == (colums - 1))
{
Console.WriteLine("");
Console.WriteLine("");
}
}
x = 0;
}
Console.ReadLine();
}
}
}
可以在Console:Console中设置光标位置。SetCursorPosition。计算光标的x/y位置应该和计算每列的行数和字符数一样简单。
您是否考虑过生成html表而不是文本表?这将避免对齐问题(浏览器将为您计算),并且不需要可读性较差的固定宽度字体;更不用说这样一个事实,你可以做一个相当花哨的格式化。
解决了这个问题,就不会有任何问题