class Beatles : IEnumerable
{
protected Enumerator enumerator = new Enumerator ();
public IEnumerator GetEnumerator ()
{
return enumerator;
}
public class Enumerator : IEnumerator
{
protected int index = -1;
protected string[] names =
{ "John", "Paul", "George", "Ringo" };
public object Current
{
get
{
if (index == -1)
index = 0; // Just in case
return names[index];
}
}
public bool MoveNext ()
{
if (index < (names.Length - 1)) {
index++;
return true;
}
return false;
}
public void Reset ()
{
index = -1;
}
}
}
IEnumrable
最新推荐文章于 2024-06-12 10:18:27 发布