I have a little misunderstanding with this sample code:
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var laterNumbers = numbers.SkipWhile((n, index) => n >= index);
“n” represents an array element. “index” represents an index of an element.
The question: How do we know that the index parameter represents exactly the index but not the element itself for instance??
Edits:
Ok, I got it. There are only 2 overloads for SkipWhile and the compiler desides which one to use whether there is one or two input parameters.
Badly formulated question)
There are only two overloads for this extension method differing only in the predicate they take. One predicate takes a single value (the item in the enumerable), the other takes the item in the enumerable and an int representing the index.
There is no confusion. If the predicate takes two parameters then the second is the index. If you pass only one parameter then it must be the item from the enumerable.