//看看 这个 你应该会知道!
using System;
using System.Collections;//这个用来 调用ArrayList
namespace ArrayList1
{
    
class Class1
{
        
[STAThread]
static void Main(string[] args)
{
            
ArrayList myAll=new ArrayList();//定义一个ArrayList动态数组myAll
int temp;
Console.WriteLine("这是一个计算输入数之和的程序!!");
Console.WriteLine("请输入要累加的数字:"); do
{
temp=Convert.ToInt32(Console.ReadLine());
myAll.Add(temp);  }while(temp!=-1);
int b=0; foreach(int temp2 in myAll)
{
b+=temp2;
                
}
Console.WriteLine("结果是:{0}",b);                
}
}
}

解决方案 »

  1.   

    只知道一维的大小,你可以声明一个不规则二维数组
    例如int[][] Matrix = new int[rows][];然后在要用的时候才声明第二维的大小
    Matrix[1] = new int[rows];你可以用一个foreach 初始化
    foreach(int[] row in Matrix)
        row = new int[length];然后就像C++的一个二维数组来用C#提供的不规则数组说白了就是数组的数组
    至于是不是真正的不规则,没有任何关系
      

  2.   

    Ninputer(装配脑袋) :
        不要乱讲!
      

  3.   

    使用ArrayList可以的像hertcloud(重载⊙DNA→)说的那样。
      

  4.   

    用ArrayList.ArrayList a;for(int i= 0; i < a.Length; i++)
    {
    Random r= new Random();
    int len = r.Next(20);
    ArrayList b = new ArrayList();
    for(int j = 0; j < len; j++)b.Add(new Object());
    a.Add(b);
    }
      

  5.   

    动态是要付出代价的!
    你知道ArrayList比固定数组慢多少倍吗??
    还在那里ArrayList,ArrayList的