Search code examples
c#iteratorienumeratorpeek

Is there a "HasNext" method for an IEnumerator?


With Java Iterators, I have used the hasNext method to determine whether an iteration has more elements (without consuming an element) -- thus, hasNext is like a "Peek" method.

My question: is there anything like a "hasNext" or "Peek" method with C#'s generic IEnumerators?


Solution

  • No, unfortunately there isn't.

    The IEnumerator<T> interface only exposes the following members:

    Methods:

    Dispose
    MoveNext
    Reset

    Properties:

    Current