Return an empty IEnumerator

Posted by Rekreativc on Stack Overflow See other posts from Stack Overflow or by Rekreativc
Published on 2009-11-11T10:35:45Z Indexed on 2010/03/17 11:21 UTC
Read the original article Hit count: 298

Filed under:
|

Hello!

I have an interface that, among other things, implements a "public IEnumerator GetEnumerator()" method, so I can use the interface in a foreach statement.

I implement this interface in several classes and in one of them, I want to return an empty IEnumerator. Right now I do this the following way:

public IEnumerator GetEnumerator()
{
    ArrayList arr = new ArrayList();
    return arr.GetEnumerator();
}

However I consider this an ugly hack, and I can't help but think that there is a better way of returning an empty IEnumerator. Is there?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ienumerator