I have an array of integers that must change its value every time a function executes it.
The problem arises every time it is executed, when going from number 1, it tells me Index was outside the bounds of the array
This is my code:
private const int n = 3;
private const int k = 4;
private static int[] workArr;
for (int i = 1; i <= 4; i++)
{
int size = (int)Math.Pow(2, i);
workArr = new int[i];
GenerateVariationsWithRep(i); //aqui es donde se cae y me muestra el error
}
private static void GenerateVariationsWithRep(int length, int index = 0)
{
for (int i = 1; i <= n; i++)
{
workArr[index] = i; //selon el debug, me dice que aqui esta mal cuando index e i son iguales a 1
GenerateVariationsWithRep(index + 1, length);
}
}
What I look for is every time the function GenerateVariationsWithRep()
is executed the array workArr
changes and assigns the values 1,2 and 3.
How could I fix it?
Thanks