IEnumerator specification inconsistency?

A

Adam Badura

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Adam said:
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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top