Is there a built-in way to convert IEnumerator to IEnumerable

前端 未结 8 1805
面向向阳花
面向向阳花 2020-12-30 18:55

Is there a built-in way to convert IEnumerator to IEnumerable?

8条回答
  •  滥情空心
    2020-12-30 19:10

    As Jason Watts said -- no, not directly.

    If you really want to, you could loop through the IEnumerator, putting the items into a List, and return that, but I'm guessing that's not what you're looking to do.

    The basic reason you can't go that direction (IEnumerator to a IEnumerable) is that IEnumerable represents a set that can be enumerated, but IEnumerator is a specific enumeratation over a set of items -- you can't turn the specific instance back into the thing that created it.

提交回复
热议问题