lundi 12 août 2019

In .NET, why does the IEnumerable abstraction exist, if it is only getting an IEnumerator object?

Why do I need IEnumerable as an abstraction other than "that's the way it was designed" and everything is expecting IEnumerable in their signature? Couldn't they have started with IEnumerator and never made IEnumerable?

I have read various SO questions, but I am still not sure of the answer. It seems to be historical in nature. I am not asking how anything works per se or how to iterate things. I am only asking why IEnumerable exists instead of only IEnumerator. Why does the abstraction of IEnumerable exist?

Why implement IEnumerable(T) if I can just define ONE GetEnumerator?

Why can't I use the enumerator of an array, instead of implementing it myself?

Can anyone explain IEnumerable and IEnumerator to me?

Aucun commentaire:

Enregistrer un commentaire