创建多维ArrayList的方法
来源:互联网 发布:python访问字典 编辑:程序博客网 时间:2024/06/10 08:36
ArrayList 类:使用大小可按需动态增加的数组实现 IList 接口。
关于定义多维数组的方法很多,但是定义ArrayList 类本人在网上查找了很久也查不到定义的方法,最后,还有人说ArrayList 类不支持多维,但是,一次调试中,我发现事实并不是这样。我定义了如下二维数组,但并没有报错。
public ArrayList[,] aa = new ArrayList[9, 9];
然而,初始化的时候就报错了。程序运行到
aa[i, j].Add((Object)1);
程序报错:“未将对象引用设置到对象的实例。”再一看定义的数组元素,值全为null,一想可能还没有NEW,于是把各个元素都NEW一遍,果然成功了。完整代码如下:
public ArrayList[,] aa = new ArrayList[9, 9];
for (int i = 0; i < 9; i++)
...{
for (int j = 0; j < 9; j++)
...{
aa[i, j] = new ArrayList();
aa[i, j].Add((Object)1);
}
}
for (int i = 0; i < 9; i++)
...{
for (int j = 0; j < 9; j++)
...{
aa[i, j] = new ArrayList();
aa[i, j].Add((Object)1);
}
}
- 创建多维ArrayList的方法
- js的创建多维数组的方法
- 动态创建多维数组的方法
- vector创建多维数组的集中方法
- Python中创建一个多维数组的方法
- [Python3]创建多维list并赋值的两种方法
- 多维转一维的方法
- ArrayList和多维数组
- CODEDOM中创建多维数组的应用
- ArrayList的Contains方法
- ArrayList的toString()方法
- list arraylist的方法
- ArrayList的contains方法
- ArrayList的contains方法
- ArrayList的toArray方法
- ArrayList的clone方法
- ArrayList的contains方法
- ArrayList的一些方法
- 声音播放速度为何超快
- [转]IP地址异形
- c语言中的指针专题
- D3DX8指南07_索引顶点
- CSS Properties To JavaScript Reference Conversion
- 创建多维ArrayList的方法
- 写个Blog测试
- 数据结构
- 最近
- uclinux在44B0上的移植
- C指针应用常见缪误
- C#事件标准步骤
- C#数据结构篇(一)线性表
- JavaScript密码强度检测源代码