change the iteration direction of the loop

You could use the ternary if and some simple arithmetic on the index to achieve this.

for (int i = 0; i < items.Count; i++)
    yield return i <= index ? items[index - i] : items[i];

Result:

Item3
Item2
Item1
Item4
Item5

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top