什么是迭代器?
迭代器是方法、get访问器或运算符,它能使您能够在类或者结构中支持foreach迭代,而不必实现整个IEnumerable接口。
例子:
publicclassYieldTest
...{
publicstaticIEnumertablePower(intnumber,intexponent)
...{
intcounter=0;
intresult=1;
while(counter++<exponent)
...{
result=result*number
yieldreturnresult
}
}
}
<!--[if !supportLists]-->1. <!--[endif]-->迭代器是可以返回相同类型的值的有序序列的一段代码
<!--[if !supportLists]-->2. <!--[endif]-->迭代器可用作方法、运算符或get访问器的代码体
<!--[if !supportLists]-->3. <!--[endif]-->迭代器代码使用yield return语句一次返回每个元素
<!--[if !supportLists]-->4. <!--[endif]-->yield break将终止迭代
<!--[if !supportLists]-->5. <!--[endif]-->可以在类中实现做个迭代器。每个迭代器都必须像任何类成员一样有唯一的名称,并且可以在foreach语句中可调用
<!--[if !supportLists]-->6. <!--[endif]-->迭代器的返回类型必须为IEnumerable、IEnumberator、IEnumerbale<T>或者IEnumberator<T>
foreach(int i in YieldTest. Power)
{
}
分享到:
相关推荐
12-iterators-and-generators(迭代器和生成器12).pdf
除锈剂演示基本的Rust迭代器用法。 本教程的目的是为一些常见的迭代器模式提供方便的参考。 它并不打算代替或描述的核心迭代器概念的概述。 实际上,本教程依赖于这两种资源。 为了充分利用此处介绍的材料,建议您...
回溯迭代器回溯迭代器:Preoder / Postorder / Inorder / BFS / Zipper
Iterall是一个可以用在所有JavaScript环境中的迭代器(Iterators)。JavaScript Iterators for allIterall提供了一些重要的实用工具,用于在所有的Javascript环境中实现和使用迭代变量(Iterables)与类数组(Array-...
Iterators.jl:常见的功能迭代器模式。 不赞成使用IterTools.jl
Typescript中的惰性迭代器 JavaScript迭代器很烂... const it = Iter . fromArray ( [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' ] ) . enumerate ( ) . map ( ( [ k , v ] ) => ...
一、迭代器Iterators 迭代器仅是一容器对象,它实现了迭代器协议。它有两个基本方法: 1)next方法 返回容器的下一个元素 2)__iter__方法 返回迭代器自身 迭代器可使用内建的iter方法创建,见例子: 复制代码 代码...
Chapter 3: Functions, Iterators, And Generators Chapter 4: Working With Collections Chapter 5: Higher-Order Functions Chapter 6: Recursions And Reductions Chapter 7: Additional Tuple Techniques ...
迭代器 这是的源代码库 版权所有:2015 许可证:
迭代工具额外的迭代器适配器、函数和宏。请在此处阅读API 文档如何与货物一起使用:[dependencies ]itertools =" 0.10.0"如何在您的板条箱中使用:use itertools:: Itertools;如何贡献修复错误或实现新事物包括对新...
Mark Pilgrim's Dive Into Python 3 is a hands-on guide to Python 3 (the ...* Example programs completely rewritten to illustrate powerful new concepts now available in Python 3: sets, iterators, generat
itertools:额外的迭代器适配器,迭代器方法,自由函数和宏
js-iterators(零依赖) JS中的Ruby样式迭代器。 JS中的Ruby样式范围[ ... 1. . _10 ] ; // [1, 2, 3, 4, 5, 6, 7, 8, 9][ ... 1. . _ - 10 ] ; // [1, 0, -1, -2, ..., -9][ ... Math . PI . _9 ] ; // [3....
Standard Template Library (STL): Containers, Iterators and Algorithms I/O, Types, Control Statements, Functions Arrays, Vectors, Pointers, References String Class, C-Style Strings Operator ...
EasyIterator:made简化迭代器! 设计和使用C ++迭代器的零成本抽象
IterTools.jl:常见的功能迭代器模式
下划线 Arity 迭代器 这个包扩展了 underscore,以添加 Underscore 提供的许多集合迭代器的 arity-bound 等价物。 又名map1和朋友。 安装 npm install underscore-arity-iterators 或者,下载单个underscore.arity...
Itrerator_pbms 该文件具有不同的迭代器实现 peek Iterators :这将具有 peek 方法来返回 peek 值。... IteratorOfIterators :这是迭代器列表迭代器的代码。 DeepIterators :这是迭代其中的集合和对象的集合。
The iterators returned by this class's个 iterator和listIterator方法是快速失败的 :如果列表在任何时间从结构上修改创建迭代器之后,以任何方式除非通过迭代器自身remove种或add方法,迭代器都将抛出一个...
散客课程即将举行的SPL迭代器课程的代码