IEnumerator与IEnumerable探讨 (续)
代码优先
public class NewMyClass : IEnumerable, IEnumerator
{
private string[] Info;
private int Index;
public NewMyClass(int Size)
{
Index = -1;
Info = new string[Size];
for (int i = 0; i < Size; i++)
{
Info[i] = i.ToString();
}
}
public object Current { get { return Info[Index]; } }
public void Reset()
{
Index = -1;
}
public bool MoveNext()
{
Index++;
return Index >= Info.Length ? false : true;
}
public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
}
以上是结合后的代码