Here is my code
public static int[] MoveZeroes(int[] arr)
{
// TODO: Program me
int zeroCount = 0;
int[] temp = { };
int numberItems = 0;
foreach (var a in arr)
{
if (a == 0)
{
zeroCount += 1;
}
else
{
temp[numberItems] = a;
}
numberItems += 1;
}
return new int[] { };
}
i use it like
int[] f = MoveZeroes(new int[] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0});
But this is giving me error Index was outside the bounds of the array
on line
temp[numberItems] = a;
how can i add items in array? what am i doing wrong ?