Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a bidirectional enumerator in C#

Is there a way to use yield blocks to implement an IEnumerator<T> which can go backward (MoveLast()) as well as forward?

like image 404
Alexey Romanov Avatar asked Jan 16 '09 16:01

Alexey Romanov


1 Answers

Not directly from the iterator block, no.

However, the caller can always buffer the results, for example into a List<T>, or just call Reverse() - but this doesn't always apply.

like image 196
Marc Gravell Avatar answered Sep 19 '22 22:09

Marc Gravell