如何接收我在c#中放入二维数组的输入



我正在制作一个二维数组(足球矩阵),我已经制作了数组、数据列和行。

如何使我的矩阵如下所示?并在各处获得正确的输入

2010-2011     England   Germany   Holland   Spain   Germany   Russia   Japan
England         x
Germany                    x
Holland                             x
Spain                                         x
Germany                                               x
Russia                                                          x
Japan                                                                    x

这一切都将被制作成一个控制台应用程序。

致问候,

int rows = 8;
int colums = 8;
String[,] data = new String[colums, rows];
int x = 0;
int y = 0;
for(; y < rows; y++)
{
    for (; x < colums; x++)
    {
        Console.Write(data[x, y] + " ");
        if (x == (colums - 1))
        {
            Console.WriteLine("");
            Console.WriteLine("");
        }
    }
    x = 0;
}
int userSelectedHomeTeam
int userSelectedAwayTeaM
Console.WriteLine("Select home team by the number")
for(int i = 1; i < colums; i++)
{   
    Console.WriteLine(data[i, 0] + " " + i)
}
str = Console.ReadLine(); 
userSelectedHomeTeam = Int32.Parse(str);
Console.WriteLine("Select away team by the number")
for(int i = 1; i < colums; i++)
{   
    Console.WriteLine(data[i, 0] + " " + i)
}
str = Console.ReadLine(); 
userSelectedAwayTeam = Int32.Parse(str);
Console.WriteLine("Write user input")
str = Console.ReadLine(); 
data[userSelectedHomeTeam , userSelectedAwayTeam ] = str;

要输出它,只需要:

int numberRows = dataArray.GetUpperBound(0);
int numberColumns = dataArray.GetUpperBound(1);
for (int i = 0; i <= numberRows ; i++)
{
    for (int j = 0; j <= numberColumns ; j++)
    {
        Console.WriteLine(string.Format("({0,8}) ", dataArray[i, j]));
    }
Console.WriteLine();
}

只需对输出使用字符串填充,以便每列数据都显示在正确的团队名称下,我已经使用了8。您需要根据每列的宽度进行调整。

相关内容

  • 没有找到相关文章

最新更新