的IEnumerator和IEnumerable之间的区别是什么? [英] What is the difference between IEnumerator and IEnumerable?
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/558304/can-anyone-explain-ienumerable-and-ienumerator-to-me">Can谁能解释IEnumerable和IEnumerator的给我吗?
什么是的IEnumerator之间的差异的IEnumerable
What are the differences between IEnumerator and IEnumerable?
推荐答案
的IEnumerable 一>是定义了一个方法的GetEnumerator 返回一个 <一个接口href="http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.aspx">IEnumerator接口,这反过来又使只读访问的集合。实现IEnumerable的集合,可以使用一个foreach语句。
IEnumerable is an interface that defines one method GetEnumerator which returns an IEnumerator interface, this in turn allows readonly access to a collection. A collection that implements IEnumerable can be used with a foreach statement.
定义
IEnumerable
public IEnumerator GetEnumerator();
IEnumerator
public object Current;
public void Reset();
public bool MoveNext();
这篇关于的IEnumerator和IEnumerable之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!