空数组怎么能赋值呢?
newarray[j]=...
c#里的Array是固定长度的,第一次赋值操作就要指定长度。要创建不定数组可以用:
System.Collections.ArrayList;
System.Collections.Stack;
System.Collections.Queue;
newarray[j]=...
c#里的Array是固定长度的,第一次赋值操作就要指定长度。要创建不定数组可以用:
System.Collections.ArrayList;
System.Collections.Stack;
System.Collections.Queue;
如果知道数组的长度则,开始赋值时一定要指明(个数).
newarray[j]={1,2,2,0,2,2,2}
创建了以后不能在改变他的大小!
用ArrayList就可以动态创建数组!using System;
using System.Collections;
,,,,,,,,,,,,,,,,,,,,,
static void Main(string[] args)
{
string answer="Y";
ArrayList newarray=new ArrayList();
for(int j = 0; answer.Equals("Y"); j ++)
{
newarray.Add(Convert.ToInt32(Console.ReadLine()));
Console.WriteLine("is it enough? Y)es N)o");
Console.WriteLine(newarray[j]);
answer = Console.ReadLine().ToUpper();
}
}