本文整理汇总了C#中System.Collections.Generic.IEnumerator<T>接口的典型用法代码示例。如果您正苦于以下问题:C# IEnumerator<T>接口的具体用法?C# IEnumerator<T>怎么用?C# IEnumerator<T>使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IEnumerator<T>接口属于System.Collections.Generic命名空间,在下文中一共展示了IEnumerator<T>接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BoxEnumerator
// Defines the enumerator for the Boxes collection.
// (Some prefer this class nested in the collection class.)
public class BoxEnumerator : IEnumerator<Box>
{
private BoxCollection _collection;
private int curIndex;
private Box curBox;
public BoxEnumerator(BoxCollection collection)
{
_collection = collection;
curIndex = -1;
curBox = default(Box);
}
public bool MoveNext()
{
//Avoids going beyond the end of the collection.
if (++curIndex >= _collection.Count)
{
return false;
}
else
{
// Set current box to next item in collection.
curBox = _collection[curIndex];
}
return true;
}
public void Reset() { curIndex = -1; }
void IDisposable.Dispose() { }
public Box Current
{
get { return curBox; }
}
object IEnumerator.Current
{
get { return Current; }
}
}