如何创建列表℃的阵列;诠释>在C#中?阵列、列表、GT

2023-09-04 12:00:12 作者:一路有你ヽ苦一點也愿意

我有一个问题,我需要ArrayList的数组。

例如,如果我们带参数的ArrayList的数组,这将是这样的:

  INT []<列表> myData的=新INT [2]其中,列表&gt ;;

myData的[0] =新的名单,其中,INT>();
myData的[0]。新增(1);
myData的[0]。新增(2);
myData的[0]。新增(3);


myData的[1] =新的名单,其中,INT>();
myData的[1]。新增(4);
myData的[1]。新增(5);
myData的[1]。新增(6);

myData的[0]。新增(7);
 

在C#中,我们如何实现像上面的一个数据结构?

ATT CK 概念及学习笔记

在C,它像链表的数组。我怎么可以做同样的在C#?

解决方案

  VAR的myData =新的名单,其中,INT> []
{
    新的List< INT> {1,2,3},
    新的List< INT> {4,5,6}
};
 

I have a problem where I need an array of arrayList.

For example if we take an Array of ArrayList of int, it will be like:

int[]<List> myData = new int[2]<List>;

myData[0] = new List<int>();
myData[0].Add(1);
myData[0].Add(2);
myData[0].Add(3);


myData[1] = new List<int>();
myData[1].Add(4);
myData[1].Add(5);
myData[1].Add(6);

myData[0].Add(7);

How can we implement a datastructure like the above in C#?

In C, its like a array of LinkedList. How can I do the same in C#?

解决方案

var myData = new List<int>[]
{
    new List<int> { 1, 2, 3 },
    new List<int> { 4, 5, 6 }
};