Hi,
Below is the declaration at class level.
int[] PossibleValues = new int[6];
int[][] JaggedArray = new int[50][];
int JaggedVar = 0;
Then in a function, I am assigning PossibleValues array to Jaggedarray like this.
[PossibleNumbers is a function that returns an array of possible numbers for a cell in a grid.]
PossibleValues = PossibleNumbers();
JaggedArray[jaggedVar] = PossibleValues;
jaggedVar++;
The number of elements in PossibleValues in each iteration may vary,but it will never exceed 6.I dont want Jaggedarray to store zeros of PossibleValues so I changed the code to:
PossibleValues = PossibleNumbers();
for (int i = 0; i < PossibleValues.Length; i++)
{
if (PossibleValues[i] != 0)
{
JaggedArray[jaggedVar][i] = new PossibleValues[i];
}
}
jaggedVar++;
But this gives null reference exception at
JaggedArray[jaggedVar][i] = new PossibleValues[i];
I searched it over the internet and came to know that JaggedArray remains null hence values cannot be assigned this way.How to resolve this?
Any help would be appreciated.
Thanks in advance!