I am implementing ICollection< T > and there are problems doing enumerator implementation.
I understand that IEnumerator< T > has to implement IEnumerator for back-compatibility (.NET 1.0)
But If i am implementing IEnumerator< T >, then there are 2 Current Properties.
I have 2 questions:
What should be their relation ? Is following code correct ?
T IEnumerator<T>.Current { get { if (_cursor < 0 || _cursor >= _array.Length) throw new InvalidOperationException("Iterator position invalid"); else return _array[_cursor]; } } object IEnumerator.Current { get { return IEnumerator<T>.Current; } }
I get this error: An object reference is required for the non-static field, method, or property 'System.Collections.Generic.IEnumerator.Current.get'
(2). Why IEnumerator< T > has to implement IDisposable. Dispose is for unmanaged resources, but in what scenario in-general would Enumerator use unmanaged resources ?