IEnumerable Interface
Learn how the foreach loop works.
We'll cover the following...
Introduction
Now’s a good time to explore how the foreach loop works. When we iterate using a for loop, we determine how that iteration works. How does the foreach loop know what the first and subsequent items are? How does it determine when there are no more items in the collection?
Know that foreach loops aren’t magic. Types that want to be iterated using a foreach loop must implement the IEnumerable interface:
The IEnumerable<T> interface
Non-generic collections can also be iterated with a
foreachloop. Non-generic collections implement theIEnumerableinterface, while generic collections utilize the generic collections use the generic ...
Ask