本文整理汇总了C#中System.Collections.IEnumerator.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerator.Reset方法的具体用法?C# IEnumerator.Reset怎么用?C# IEnumerator.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.IEnumerator
的用法示例。
在下文中一共展示了IEnumerator.Reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PeopleEnum
// When you implement IEnumerable, you must also implement IEnumerator.
public class PeopleEnum : IEnumerator
{
public Person[] _people;
// Enumerators are positioned before the first element
// until the first MoveNext() call.
int position = -1;
public PeopleEnum(Person[] list)
{
_people = list;
}
public bool MoveNext()
{
position++;
return (position < _people.Length);
}
public void Reset()
{
position = -1;
}
object IEnumerator.Current
{
get
{
return Current;
}
}
public Person Current
{
get
{
try
{
return _people[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
示例2: IEnumerator.Reset()
//引入命名空间
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
ArrayList myArrayList = new ArrayList();
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
string[] anotherStringArray = {"Here's", "some", "more", "text"};
myArrayList.SetRange(0, anotherStringArray);
Console.WriteLine("Using the GetEnumerator() method to get an enumerator");
IEnumerator myEnumerator = myArrayList.GetEnumerator();
while (myEnumerator.MoveNext())
{
Console.WriteLine("myEnumerator.Current = " + myEnumerator.Current);
}
myEnumerator.Reset();
myEnumerator.MoveNext();
Console.WriteLine("myEnumerator.Current = " + myEnumerator.Current);
}
}