Enumerables,IteratorsandYield:可枚举,迭代器和产量

更新时间:2023-06-03 22:25:18 阅读: 评论:0

Enumerables, Iterators and Yield
Enumerators
An enumerator works over a quence, and is considered to have a concept of “before the first element”, the t of elements, and another concept of “after the last element”
An enumerator also has a current position, which is changed by calling the MoveNext method
An enumerator's Current property returns the element at the current position, or if accesd when the current position is “before the first element”
太学士
or “after the last element”, throws an exception
...
Before the first element After the last element Current position
Enumerators
System.Collections.IEnumerable has one method
●IEnumerator GetEnumerator();
System.Collections.IEnumerator has two methods and one property
●object Current: returns reference to the element at the current position
(note the return type is object [not type safe])
●void Ret(): rets the current position to “before the first element”
中级论文●bool MoveNext(): either changes current to refer to the next element (and returns true),
or “after the last element” if no more available (and returns fal)
[Enumerator is initialid to “before the first element”, so MoveNext must be called to have Current refer to first element]
Enumerators
also has type-safe generic versions of enumerable and enumerator ●System.Collections.Generic.IEnumerable<T> has one method萨莫耶
曲组词
●IEnumerator<T> GetEnumerator();
院感知识培训
System.Collections.Generic.IEnumerator<T> had one method and one property
●bool MoveNext(): advances the current position
●T Current: returns type-safe reference to the element at the current position Note there is no Ret method
Notes on Enumerators
苏教版五年级数学Enumerators are read-only
Ud to read elements, but not to t them
Not synchronid
玫瑰与夜莺foreach keyword in C# and for each in VB requires that a collection supports the IEnumerable interface
蛇和什么生肖最配
An enumerator is only valid while the underlying quence does not change C# iterators work with the Enumerator concept

本文发布于:2023-06-03 22:25:18,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/852667.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:院感   苏教版   玫瑰   知识   数学   夜莺
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图