I tried to see the code of both interfaces, but the only difference I see is IEnumerable<T>
has method IEnumerator<T> GetEnumerator();
, and that in interface IEnumerator<T>
Current
returns "T" instead of object ...
Would this be just to prevent the foreach from doing an unboxing afterwards? or not?
And another question, do you usually make another class even to implement the interface IEnumerator
and implement all the methods MoveNext, Reset, Current, etc ... or just implement IEnumerable<T>
and return a GetEnumerator () from List already enough?
Example:
public IEnumerator<Error> GetEnumerator()
{
return this._errors.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this._errors.GetEnumerator();
}
GetEnumerator()
is an Array Class method that returns to us a class that implements IEnumerator<T>
same?