为什么我们需要在C#迭代器? [英] Why do we need iterators in c#?

查看:101
本文介绍了为什么我们需要在C#迭代器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以提供使用迭代器的一个活生生的例子。我试着搜索谷歌,但没有满意的答案。

Can somebody provide a real life example regarding use of iterators. I tried searching google but was not satisfied with the answers.

推荐答案

迭代器是分离出来的位置概念集合中的抽象从集合本身。迭代器是一个单独的对象存储必要的状态集合中找到一个项目,然后移动到下一个项目收藏。我已经看到,保持集合(即当前位置)里面的那个状态集合,但它往往是最好的状态转移到外部对象。除此之外它使您能够拥有多个迭代器遍历相同的集合。

Iterators are an abstraction that decouples the concept of position in a collection from the collection itself. The iterator is a separate object storing the necessary state to locate an item in the collection and move to the next item in the collection. I have seen collections that kept that state inside the collection (i.e. a current position), but it is often better to move that state to an external object. Among other things it enables you to have multiple iterators iterating the same collection.

这篇关于为什么我们需要在C#迭代器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆