, IEnumerable. , , 99% .
, , IEnumerable, GetEnumerator() , IEnumerator , foreach. Ienumerator , , "" ", , foreach" ". , Enumerator ( IEnumerator IEnumerator)
( PersonCollection)
public IEnumerator GetEnumerator() { return new myTypeEnumerator(this); }
public class myTypeEnumerator : IEnumerator
{
int nIndex;
PersonCollection pers;
public myTypeEnumerator(PersonCollection myTypes)
{ pers = myTypes; nIndex = -1; }
public bool MoveNext() { return (++nIndex < pers.alPers.Count); }
public object Current { get { return (pers[nIndex]); } }
public void Reset() { nIndex = -1; }
}
, :
public IEnumerator<T> GetEnumerator() { return new myTypeEnumerator<T>(this); }
public class myTypeEnumerator<T> : IEnumerator<T>
{
int nIndex;
IList<T> tList;
public myTypeEnumerator(IList<T> listOfTs)
{
tList = listOfTs;
nIndex = -1;
}
public bool MoveNext() { return (++nIndex < tList.Count); }
public T Current { get { return (tList[nIndex]); } }
public void Reset() { nIndex = -1; }
}