When IEnumerator.Reset() method is called?

后端 未结 6 625
醉话见心
醉话见心 2021-01-11 14:51

let\'s have this code :

class MyList : IEnumerable, IEnumerator
{
    int[] A = { 1, 2, 3, 4, 5 };
    int i = -1;

    #region IEnumerator Members

    pub         


        
6条回答
  •  忘掉有多难
    2021-01-11 15:31

    Reset is redundant; so much so that it is a requirement in the language spec for iterator blocks to throw an exception on Reset. The correct thing to do is simply dispose and release the old iterator, and call GetEnumerator again. Or better: avoid having to read it twice, since not all data is repeatable.

提交回复
热议问题