我有一個數組,範圍從-100到100之間的數字。現在,我必須創建一個方法,將正數複製到另一個數組中。 我做了這個:C#無法訪問的代碼(與屬性有關的數組複製器)
static int[] ArrayCopy(int[] t)
{
int a = 0;
int[] g = new int[0];
for (int i = 0; i < t.Length; i++)
{
if (t[i] > 0)
{
g[a] = t[i];
a++;
}
}
return g;
}
該程序將終止IndexOutOfRange,我不明白這一點。
謝謝,它的工作! – user3365304