What is the difference between IEnumerator and IEnumerable?

Shaun picture Shaun · Mar 6, 2009 · Viewed 158.5k times · Source

Possible Duplicate:
Can anyone explain IEnumerable and IEnumerator to me?

What are the differences between IEnumerator and IEnumerable?

Answer

cgreeno picture cgreeno · Mar 6, 2009

IEnumerable is an interface that defines one method GetEnumerator which returns an IEnumerator interface, this in turn allows readonly access to a collection. A collection that implements IEnumerable can be used with a foreach statement.

Definition

IEnumerable 

public IEnumerator GetEnumerator();

IEnumerator

public object Current;
public void Reset();
public bool MoveNext();

example code from codebetter.com