How Can I Use IEnumerator.Reset()?

前端 未结 3 1179
春和景丽
春和景丽 2020-12-05 13:15

How exactly is the right way to call IEnumerator.Reset?

The documentation says:

The Reset method is provided for COM interoperabi

3条回答
  •  时光说笑
    2020-12-05 14:08

    never; ultimately this was a mistake. The correct way to iterate a sequence more than once is to call .GetEnumerator() again - i.e. use foreach again. If your data is non-repeatable (or expensive to repeat), buffer it via .ToList() or similar.

    It is a formal requirement in the language spec that iterator blocks throw exceptions for this method. As such, you cannot rely on it working. Ever.

提交回复
热议问题