如何将输入放在正确的列下方以及正确的行之外?

时间:2011-06-22 12:22:39

标签: c# multidimensional-array matrix coordinates

这是我的二维表的代码。

我想要做的是将输入放在正确的位置 - 但正如您所看到的,我对表的输出并不是应该的。列与行重叠。 我的问题是:如何将列更多地放在右边。而且 - 我怎样才能在正确的位置上得到我的输入?

一些提示和帮助表示赞赏。

        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();




        }
    }
}

3 个答案:

答案 0 :(得分:1)

可以在控制台中设置光标位置:Console.SetCursorPosition。确定光标的x / y位置应该像计算每列的行数和字符一样简单。

答案 1 :(得分:0)

您是否考虑过生成html表而不是文本表?这将避免对齐问题(浏览器将为您计算),并且不需要不太可读的固定宽度字体;更不用说你可以做更有趣的格式化了。

答案 2 :(得分:-1)

Raed this你没有问题

相关问题