IEnumerable & IEnumerator

class MyClass:IEnumerator,IEnumerable
{
int[] dates;
int ipoint;

public MyClass()
{
dates
=new int[] {1,2,4,3,6,5,7,8,9,0,9};
ipoint
= 0;
}
#region IEnumerator 成员

public object Current
{
get { return dates[ipoint]; }
}

public bool MoveNext()
{
ipoint
++;
if (ipoint==10)
{
return false;
}
return true;
}

public void Reset()
{
ipoint
= 0;
}

#endregion

#region IEnumerable 成员

public IEnumerator GetEnumerator()
{
return this;
}

#endregion
}
posted @ 2011-05-12 22:43  木由水  阅读(172)  评论(0编辑  收藏  举报