I have an array numArray
with the length set to a value the user can put in. if arrayLength
is 5 for example I want the for loop to count up by 1 to 5 [1,2,3,4,5]. My error is numArray[i] = sum + 1;
(System.IndexOutOfRangeException: 'Index was outside the bounds of the array.')
int[] numArray = new int[arrayLength];
int sum = 0;
for (int i = 0; i <= arrayLength; i++)
{
Console.WriteLine(i);
numArray[i] = sum + 1;
}