的IEnumerator和IEnumerable之间的区别是什么? [英] What is the difference between IEnumerator and IEnumerable?

查看:346
本文介绍了的IEnumerator和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();

例如$ C $从codebetter.comÇ

这篇关于的IEnumerator和IEnumerable之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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