public bool MoveNext() { do { if (version != list.version) { throw new InvalidOperationException("Collection modified"); } if (index > 0 && Current != null // only works for values that are set, otherwise the index is buried in the free index stack somewhere ) { int freeIndex = list.freeIndices.Peek(); if (freeIndex < index) { list.freeIndices.Pop(); list[freeIndex] = list[index]; list.RemoveAt(index); } } index++; return(index < list.Count); } while (Current == null); }
/// <summary> /// Accessing Current after RemoveCurrent may throw a NullReferenceException or return null. /// </summary> public void RemoveCurrent() { list.RemoveAt(index); }