IEnumerable announces the signature of a method:
GetEnumerator()
which returns an instance that implemented IEnumerator.
IEnumerator announces the signatures of 3 methods:
Current()
MoveNext()
and Reset()
which helps the foreach loop to enumerate the contents of the collection.
For example,
foreach (var p in persons)
{
Console.WriteLine(p);
}
will be compiled into the following code...
IEnumerator < Person > enumerator = persons.GetEnumerator();
while (enumerator.MoveNext())
{
Person p = enumerator.Current;
Console.WriteLine(p);
}
The collection `persons' has to implement GetEnumerator() which returns an instance that implements MoveNext() and Current(), and Reset() although not shown in the example.