IEnumerable
and IEnumerator
are both interfaces. IEnumerable
has just one method called GetEnumerator
. This method returns (as all methods return something including void) another type which is an interface and that interface is IEnumerator
. When you implement enumerator logic in any of your collection class, you implement IEnumerable
(either generic or non generic). IEnumerable
has just one method whereas IEnumerator
has 2 methods (MoveNext
and Reset
) and a property Current
. For easy understanding consider IEnumerable
as a box that contains IEnumerator
inside it (though not through inheritance or containment). See the code for better understanding:
class Test : IEnumerable, IEnumerator
{
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public object Current
{
get { throw new NotImplementedException(); }
}
public bool MoveNext()
{
throw new NotImplementedException();
}
public void Reset()
{
throw new NotImplementedException();
}
}