im aware of Eric Lippert's blog post about situation but i think this is a different situation because the field immutates itself rather then its field. How could you explain calling MoveNext() if Enumerator was readonly doesnt show any effect and output is always 0 ?
class SomeClass
{
private List<int> list;
private [readonly] List<int>.Enumerator enumerator;
public SomeClass()
{
list = new List<int>() { 1, 2, 3 };
enumerator = list.GetEnumerator();
}
public int ReadValue()
{
if (enumerator.MoveNext())
return enumerator.Current;
return -1;
}
}
static void Main()
{
SomeClass c = new SomeClass();
int value;
while ((value = c.ReadValue()) > -1)
MessageBox.Show(value.ToString());
}