Why is IEnumerable necessary when there is IEnumerator?

后端 未结 1 1336
遥遥无期
遥遥无期 2021-02-07 03:35

Disclaimer: I understand the difference between IEnumerable and IEnumerator and how to use both. This is not a dupl

相关标签:
1条回答
  • 2021-02-07 04:34

    The two interfaces each represent very different concepts. IEnumerable<T> is something that "allows enumeration", where IEnumerator<T> is the representation of the enumeration itself.

    If you were to merge these together, it would be impossible to enumerate a single collection more than once at the same time (without some other mechanism in place). For example, two threads doing a foreach over an array would no longer work, where that is perfectly acceptable in the current design.

    0 讨论(0)
提交回复
热议问题