日期:2014-05-17  浏览次数:20951 次

如何创建动态二维数组
第一个问题:我是从数据库读值 所以不知道数组的长度 这样能创建数组吗 应该不行吧 我用的都是ArrayList
第二个问题:我知道了二维数组中第一维的个数 第二维个数是动态的 这样能创建吗  要是不能怎么解决呢 ArrayList貌似就是个一维动态数组 没法解决二维的问题啊

------解决方案--------------------
List<int[]> lst=new List<int[]>();
这样就是一个动态的二维数组
------解决方案--------------------
赋值:
lst.Add(new int[]{1,2,3});
lst.Add(new int[]{1,2,3,4,5});
lst.Add(new int[]{3,4,5});
...

提取:
int []first=lst[0];
int []second=lst[1];
int []third=lst[2];
...
------解决方案--------------------
更改赋值:
lst[0]=new int[]{11,22,33};
------解决方案--------------------
这是泛型..
------解决方案--------------------
List<string[]> lst=new List<string[]>();
跟int数组类似
------解决方案--------------------
int[,]  二维数组
int[][] 交错数组
List<T> 泛型