I want to convert the above array to a list to avoid the declaration number of elements in the array but unable to achieve it because that is obvious that if i try to do the same thing on a list i will get a index out of bound exception.. have been trying through out the day. I pasted the part of the logic here where i am facing a problem.A recursive call in a being made to the function in the base class(This shouldn’t matter to answer this question but just making it clear).
please help me out.
int[] arr = new int[100];
Dictionary<int, List<int>> dict = new Dictionary<int, List<int>>();
public override int function(int length, out List<int> cuts)
{
cuts = new List<int>();
if (length < 0)
return 0;
if (arr[length] == 0 )
{
arr[length] = base.Function(length, out cuts);
dict.Add(arr[length], cuts);
}
cuts = dict[arr[length]];
return arr[length];
}
Just expand the list if the
length(should beindex) of the “dynamic grown” list is smaller than the index (“length” in your case).