It's been asked a couple of times on SO how you can implement a bidirectional enumerator (http://stackoverflow.com/questions/191788/two-directional-list-enumerator-in-net, http://stackoverflow.com/questions/451099/implementing-a-bidirectional-enumerator-in-c). 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, arrays). So why does no such type exist?