本文整理匯總了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; }
}
}