如何在 C# 中为此创建多维列表?

Sku*_*uta 4 c# arrays list multidimensional-array

我有一个表(在文件中),我按空格将其分成块。

我需要这样的结构:

-----------------------------
|21|22|23|33|3323|
|32|32|
|434433|545454|5454|
------------------------------
Run Code Online (Sandbox Code Playgroud)

更像是每一行都是它自己的表。我该怎么做?

我试过了List<List<string>> matrix = new List<List<string>>();但我似乎找不到处理它的方法。

编辑- 有人能告诉我这段代码有什么问题吗????Matrix[0][0] 与矩阵 [1][0] .. 似乎总是向矩阵添加同一行,但我清除了它......

static ArrayList ReadFromFile(string filename)
    StreamReader SR;
    string S;
    string[] S_split;

    SR = File.OpenText(filename);
    S = SR.ReadLine();

    ArrayList myItems = new ArrayList();

    List<List<string>> matrix = new List<List<string>>();
    List<string> row = new List<string>();

    while (S != null)
    {
        row.Clear();
        S_split = S.Split(' ');
        for (int i = 1; i < S_split.GetLength(0); i++)
        {
            row.Add(S_split[i]);
            matrix.Add(row);
        }              

        S = SR.ReadLine();
    }
    Console.WriteLine(matrix[1][1]);
    SR.Close();
    return myItems;
}
Run Code Online (Sandbox Code Playgroud)

Gan*_*ant 7

不确定我是否正确理解这一点。

        List<List<int>> table = new List<List<int>>();
        List<int> row = new List<int>();
        row.Add(21);
        row.Add(22);
        row.Add(23);
        row.Add(33); // and so on
        table.Add(row);

        row = new List<int>();
        row.Add(1001);
        row.Add(1002);
        table.Add(row);

        MessageBox.Show(table[0][3].ToString());
Run Code Online (Sandbox Code Playgroud)

程序应该显示一个带有文本“33”的消息框。