问题如下:
有一个二维数组,其长度是不确定的。
如果用ArrayList来定义的话,怎么样对这个二维数组赋值。
就好比:
ArrayList arrays=new ArrayList();
之后不知道怎么样添加数据
比如要:
a[1,0]=1
a[1,1]=2
a[2,0]=11
a[2,1]=22
该怎么样将这些值赋进去呢,以及怎么样取出这些值!谢谢指导!

解决方案 »

  1.   

    ArrayList arrays=new ArrayList();
    int[] a=new int[2];
    a[0]=1;
    a[1]=2;
    arrays.add(a);
    a[0]=11;
    a[1]=22;
    arrays.add(a);
    for(int i=0;i<arrays.count;i++)
    {
       a=arrays[1];
    }
      

  2.   

    //            这样啊
    //你就改城arraylist中房一维数组就行了撒
                ArrayList arrays = new ArrayList();
                for(int i=0;i<10;i++)
                {
                    int[] a = new int[2];
                    a[0]=1;
                    a[1]=2;
                    arrays.Add(a);
                }            //读的时候
                foreach(int[] a in arrays)
                {
                    Console.WriteLine(a[0].ToString());
                    Console.WriteLine(a[1].ToString());
                }运行通过哦
      

  3.   

    using System;
    using System.Collections;class Class1
    {
    [STAThread]
    static void Main(string[] args)
    {
    MyCollection a=new MyCollection(); a[1,0]=1;
    a[1,1]=2;
    a[2,0]=11;
    a[2,1]=22; Print(a); Console.Read();
    } private static void Print(MyCollection collection)
    {
    foreach(int[] itemList in collection)
    {
    string temp = ""; foreach(int item in itemList)
    {
    temp += string.Format("{0}\t", item);
    } Console.WriteLine(temp);
    }
    } public class MyCollection : CollectionBase
    {
    private int InitSize = 1;
    public int this[int x, int y]
    {
    get
    {
    int[] temp = this[x]; if (y < temp.Length) return temp[y]; int[] newList = new int[y + 1];
    Copy(temp, newList); this.List.Remove(temp);
    this.List.Insert(x, newList); return newList[y];
    }
    set
    {
    int[] temp = this[x]; if (y < temp.Length) 
    {
    temp[y] = value;
    } int[] newList = new int[y + 1];
    Copy(temp, newList); this.List.Remove(temp);
    this.List.Insert(x, newList); newList[y] = value;
    }
    } public int[] this[int x]
    {
    get
    {
    for(int i = x + 1 - this.Count; i > 0; i--)
    {
    this.List.Add(new int[InitSize]);
    } return (int[])this.List[x];
    }
    } private void Copy(int[] from, int[] to)
    {
    for(int i = from.Length - 1, j = to.Length - 1, k = 0; i>=0 & j >= 0; i--, j--, k++)
    {
    to[k] = from[k]; 
    }
    } }
    }
      

  4.   

    TO 
    sealeft(海海)  
    jackyped(★★★★★★★★★★[我的星星是蓝色-_-!!!]) 
    xvting(xvting) ( )
    谢谢三位的解答,综合三位的意见,终于解决了问题!
    只有这么一点分了,不好意思!