kuhaku kuhaku - 2 months ago 9
C# Question

Where is the implementation of IEnumerable of Collection<T>

Suppose I have a

Collection<string>
and I'm using
GetEnumerator()
that returns
IEnumerator<string>
, where can I find the implementation of
IEnumerator
for this collection?

On MS site they just say:


Returns an enumerator that iterates through the Collection.


But where is the class that implements
IEnumerator
?

Answer

Looking into the source we can see that GetEnumerator returns the GetEnumerator of its' items field which concrete type is List<T> (inside the ctor)

That GetEnumerator returns an instance of List<T>.Enumerator an internal nested class whose source is available here

Comments