Here is the finished Enumerator class:
private class myEnumerator : IEnumerator{ private MyList myList; private int index; public myEnumerator(MyList myList) { this.myList = myList; index = -1; } public bool MoveNext() { index++; return (index < myList.Count); } public T Current { get { return myList[index]; } } object IEnumerator.Current { get { return Current; } } // Not Needed public void Dispose() { //Not Needed } public void Reset() { index = -1; } }
This new class is embedded in the List class, and it just spits out the next item in the list. The cool thing about this new Enumerator is that it will stop as soon as it reached the Count of the items in the list instead of the length of the array. This way if there are any empty slots in the array, they won't get printed in the list.
That's all for now, thanks for reading!
No comments:
Post a Comment