请问怎么定义一个不定长的数组?谢谢1

解决方案 »

  1.   

    C#不是很懂,在VB里是
    dim A() as string
    redim A(可变)
      

  2.   

    同意silentwins(原谅我当天不懂得珍惜只知任性...)
      

  3.   

    每次都new一个新的int[]不就可以了吗?
      

  4.   

    http://dev.csdn.net/develop/article/52/52336.shtm
      

  5.   

    用ArrayList,这是一个可变的存object的容器
    你就把他当数组用,要用的时候拿出来,转化为int就能用了,要存的话直接扔进去就可以了
      

  6.   

    ArrayList arr = new ArrayList();
      

  7.   

    如果你一定要用不定长的数组的话,请使用如下的类似vb的自定义方法:public static Array Redim(Array origArray,Int32 desiredSize)
    {
        Type t = origArray.GetType().GetElementType();    Array newArray = Array.CreateInstance(t,desiredSize);    Array.Copy(origArray,0,newArray,0,Math.Min(origArray.Length,desiredSize));    return newArray;
    }
      

  8.   

    ArrayList arr = new ArrayList()
    arr.Add(1);
    arr.Add(2);
    arr.Add(3);
    arr.Add(4);
    arr.Add(5);int[] intArr = new int[arr.Length];int idx = 0
    foreach(object o in arr)
    {
      intArr[idx++] = Convert.ToInt32(o);
    }
      

  9.   

    public static Array Redim(Array origArray,Int32 desiredSize)
    {
        Type t = origArray.GetType().GetElementType();    Array newArray = Array.CreateInstance(t,desiredSize);    Array.Copy(origArray,0,newArray,0,Math.Min(origArray.Length,desiredSize));    return newArray;
    }public void test()
    {
        int[] intAry = new int[0];    intAry = (int[])Redim(intAry,3);
        intAry[0] = 1;
        intAry[1] = 2;
        intAry[2] = 3;
    }
      

  10.   

    使用Array.CreateInstance方法运行时重新创建一个数组,把原数据的内容复制到新数组中并返回新数组。
      

  11.   

    int[] ldOld=new int[] 不要设长度呀
      

  12.   

    可以初始化数组的时候不指定长度吗?
    int[] i = new int[];?
    这样可以?
      

  13.   

    应该不可以,用ArrayList动态数组