IEnumerator specification inconsistency?
In MSDN (August 2006) in the specification of IEnumerator.Current there
is word on exceptions. InvalidOperationException shall be thrown in case
"The collection was modified after the enumerator was created.". But in the
remarks section it can be read that "If the collection is modified between
MoveNext and Current, Current returns the element that it is set to, even if
the enumerator is already invalidated."
For me both this sentances seem to be contradictory. Or am I mistaken?
Also another intersting thing. IEnumerator<T> does not specify
exceptions at all. In remarks section it says only when Current is
undefined.
Framework doesn't seem to do checks at all.
Adam Badura
Date:Sat, 18 Aug 2007 23:30:42 +0200
Author:
|
Re: IEnumerator specification inconsistency?
Adam Badura wrote:
> In MSDN (August 2006) in the specification of IEnumerator.Current there
> is word on exceptions. InvalidOperationException shall be thrown in case
> "The collection was modified after the enumerator was created.". But in the
> remarks section it can be read that "If the collection is modified between
> MoveNext and Current, Current returns the element that it is set to, even if
> the enumerator is already invalidated."
> For me both this sentances seem to be contradictory. Or am I mistaken?
> Also another intersting thing. IEnumerator<T> does not specify
> exceptions at all. In remarks section it says only when Current is
> undefined.
>
> Framework doesn't seem to do checks at all.
>
> Adam Badura
Yes, that is inconsistent. In the 1.1 version of the documentation, it's
consistent:
http://msdn2.microsoft.com/en-us/library/system.collections.ienumerator.current(VS.71).aspx
The implementation seems to follow the 1.1 version of the documentation.
If you for example look at the code for List<T>.Enumerator<T>.Current,
it only returns the current element without checking the list object
version:
public T Current {
get {
return this.current;
}
}
--
Gran Andersson
_____
http://www.guffa.com
Date:Sun, 19 Aug 2007 02:38:17 +0200
Author:
|