本来我是这样写的:
   short[] a;
   Console.Write("请输入共几个数字进行比较:");
   short n = short.Parse(Console.ReadLine());
   short[] a=new short[n];
报错后,我只有这样写才通过:
   Console.Write("请输入共几个数字进行比较:");
   short n = short.Parse(Console.ReadLine());
   short[] a=new short[n];
如何创建动态数组呢?难到一定要给数组赋值一个数量吗?

解决方案 »

  1.   

    正如你写的那样确实需要一个数值创建数组 int[] index = new int[10];
    动态的只是将10这个数字变成一个变量例如你在这里我想最好的写法是shor[] a = new short[n+1];
      

  2.   

    int n=20;
    string [] b=new string[n];
    b[n-1]="ok!";
      

  3.   

    本来我是这样写的: 
      short[] a; 
      Console.Write("请输入共几个数字进行比较:"); 
      short n = short.Parse(Console.ReadLine()); 
      short[] a=new short[n]; 这里错了,应该为a=new short[n];
    报错后,我只有这样写才通过: