It's been asked a couple of times on SO how you can implement a bidirectional enumerator (here, here). My question is not how (which is trivial for most cases), but why no such type exists in the .NET platform.
public interface IBidirectionalEnumerator<T> : IEnumerator<T>
{
bool MovePrev();
}
Obviously, there are many collection types which can't implement this, as MoveNext()
is destructive or changes the state of the underlying collection. But conversely, many types can implement this trivially (List
, IList
, LinkedList
, array
).
Why does no such type exist?