-1

I need to run this loop and add the values to the length array each time the loop iterates, so far each time i loop the temp array is cleared so the data is getting lost each iteration. I want to resize the array and add the user input to the length array each iteration.

int[] lengthArray = new int [1];


for (int i = 0; i < lengthArray.Length; i++)
{
    lengthArray[i] = int.Parse(Console.ReadLine());
    int[] temp = new int [lengthArray.Length + 1] ;
    temp[i] = lengthArray[i];
    lengthArray = temp;

}

1 Answers1

0

You probably want to store your result in a List<int> instead of an array int[] .

Then you each time you want to add an element in the lengthArray you can just call the Add method.

Manitra Andriamitondra
  • 1,249
  • 1
  • 15
  • 21