let's have this code :
class MyList : IEnumerable, IEnumerator
{
int[] A = { 1, 2, 3, 4, 5 };
int i = -1;
#region IEnumerator Members
public object Current
{
get { return A[i]; }
}
public bool MoveNext()
{
i++;
return i < 5;
}
public void Reset()
{
i = -1;
}
#endregion
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
#endregion
}
And In Main Method :
MyList list = new MyList();
foreach (int i in list)
{
Console.WriteLine(i);
}
foreach (int i in list)
{
Console.WriteLine(i);
}
Why the second foerach doesn't work ?? and the "i" doesn't initialize again ??
Is that true : Reset method should be called automatically before foreach is executed ??
why it doesn't call here ??