IEnumerable Interface

Implement the IEnumerable<T> and IEnumerator<T> interfaces to understand how the foreach loop iterates through custom collection types.

While standard for loops require explicit iteration logic, the foreach loop relies on an underlying structural contract to traverse a collection. To allow a custom type to be iterated using a foreach loop, that type must implement the IEnumerable interface.