实现IEnumerable接口的类,可以支持foreach循环遍历对象的集合元素

IEnumerable:
IEnumerator GetEnumerator() 返回可循环访问集合的枚举数。

IEnumerator:
object Current 获取集合中的当前元素。
bool MoveNext() 将枚举数推进到集合的下一个元素。
如果枚举数成功地推进到下一个元素,则为 true;如果枚举数越过集合的结尾,则为 false
void Reset() 将枚举数设置为其初始位置,该位置位于集合中第一个元素之前。


sample:
IEnumerable 和 IEnumerator 接口using System;
IEnumerable 和 IEnumerator 接口
using System.Collections;
IEnumerable 和 IEnumerator 接口
IEnumerable 和 IEnumerator 接口
namespace ConsoleApplication1
}

相关文章:

  • 2021-11-22
  • 2021-10-20
  • 2022-01-14
  • 2021-10-11
  • 2021-05-24
猜你喜欢
  • 2021-05-24
  • 2022-01-13
  • 2021-10-25
相关资源
相似解决方案