Are 2 dimensional Lists possible in c#?

后端 未结 9 1593
走了就别回头了
走了就别回头了 2020-11-27 12:44

I\'d like to set up a multidimensional list. For reference, I am working on a playlist analyzer.

I have a file/file-list, which my program saves in a standard list.

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 13:11

    Here is how to make a 2 dimensional list

            // Generating lists in a loop.
            List> biglist = new List>();
    
            for(int i = 1; i <= 10; i++)
            {
                List list1 = new List();
                biglist.Add(list1);
            }
    
            // Populating the lists
            for (int i = 0; i < 10; i++)
            {
                for(int j = 0; j < 10; j++)
                {
                    biglist[i].Add((i).ToString() + " " + j.ToString());
                }
            }
    
            textbox1.Text = biglist[5][9] + "\n";
    

    Be aware of the danger of accessing a location that is not populated.

提交回复
热议问题