I need help better understanding this piece of code from mosh’s solution on the string exercise, the first one where we were supposed to check if the numbers entered are consecutive.

for (i = 1; i < numbers.Count; i++)

{

if (number [i] != number[i-1] + 1) // This line, i know what it does but dont know how it works

{

is consecutive = false;

break;

}

}

Your help is greatly appreciated

list =1,2,3,4,5,7,8,9. This is a list of integers. If I want to access the first item of the list I would write list[0], if I want to access the second item I would write list[1], the third, I would write list[2]. In the for loop, we create an integer which counts the number of times the loop has repeated. So if the list is on the third repetition, the integer i=3. So if we write list[i], with 3 repetitions of the for loop, it is the same as writing list[3], which accesses the 4th element of the list. Because we start counting at 0 and not one (list[0] is the first integer on the list) then we must write list[i-1] or list[3-1] to get the third integer in the list. So what the line of code is doing is checking if the current integer in the list is not equal to the integer before it in the list when one is added to that integer. The math done inside the square brackets [], determine what element of the list we are accessing while the math outside of that is taking that integer inside the list we just accessed and doing math to it.