如何创建列表℃的阵列;诠释>在C#中? [英] How to create an array of List<int> in C#?

查看:120
本文介绍了如何创建列表℃的阵列;诠释>在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我需要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#中,我们如何实现像上面的一个数据结构?

在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 }
};

这篇关于如何创建列表℃的阵列;诠释&GT;在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆