Today I would like to talk about the way the foreach loop works inside.
We all know that a foreach loop is - a loop that iterates through all the elements of the collection. Its greatest advantage in the ease of use - we do not need to worry about how many elements in the collection. However, many do not know that this is just syntactic “sugar”, which facilitates the work of the programmer. Therefore, we simply have to know in what the resulting compiler will convert.
The foreach loop works differently, depending on the collection you want to sort through.
1) If it has to deal with the banal array, we can always know its length. Therefore, foreach will eventually be converted to a for loop. For example:
...