[Mono-list] Array.GetEnumerator()

Nick Drochak ndrochak@gol.com
Sat, 9 Mar 2002 08:28:54 +0900


| 	The docs are really confusing over this.
| <doc>
| An enumerator remains valid as long as the collection remains 
| unchanged. If changes are made to the collection, such as 
| adding, modifying, or deleting elements, the enumerator is 
| irrecoverably invalidated and the next call to MoveNext or 
| Reset throws an InvalidOperationException. 
| </doc>
| 	We *can* modify array elements.
| 	However MS implementation doesnt do this for an fixed 
| size array. So we don't need to do the versioning either ;)
| 

Well, all it took was to write a simple test case and find out (which
you obviously did, and I didn't until now)...

int[,] a = {{1,2,3,4},{5,6,7,8}};
int rank = a.Rank;
IEnumerator e = a.GetEnumerator();
int[] idxs = {0,0};
a.SetValue(9, idxs);
e.MoveNext();
int i = (int)e.Current;

This code does not throw an exception with mscorlib.  I would think it
should since I cannot find any exemption for Array's enumerator in the
docs with respect to MoveNext() after a mutation.

BTW, it doesn't throw for a single dimension array either.

So either this is an undocumented "feature" or a bug.

I'll implement the enumerator to mimic MS's behavior for now, and report
this discrepancy to them.

Nick D.