Is it possible to do start iterating from an element other than the first using foreach?

后端 未结 5 1883
花落未央
花落未央 2020-12-05 01:26

I\'m thinking about implementing IEnumerable for my custom collection (a tree) so I can use foreach to traverse my tree. However as far as I know foreach always starts from

5条回答
  •  不思量自难忘°
    2020-12-05 02:07

    Foreach will iterate over your collection in the way defined by your implementation of IEnumerable. So, although you can skip elements (as suggested above), you're still technically iterating over the elements in the same order.

    Not sure what you are trying to achieve, but your class could have multiple IEnumerable properties, each of which enumerates the elements in a specific order.

提交回复
热议问题