c# - How Can I Use IEnumerator.Reset()? -


how right way call ienumerator.reset?

the documentation says:

the reset method provided com interoperability. not need implemented; instead, implementer can throw notsupportedexception.

okay, mean i'm not supposed ever call it?

it's so tempting use exceptions flow control:

using (enumerator = getsomeexpensiveenumerator()) {     while (enumerator.movenext()) { ... }      try { enumerator.reset(); } //try inexpensive method     catch (notsupportedexception)     { enumerator = getsomeexpensiveenumerator(); } //fine, 1      while (enumerator.movenext()) { ... } } 

is how we're supposed use it? or not meant use managed code @ all?

never; mistake. correct way iterate sequence more once call .getenumerator() again - i.e. use foreach again. if data non-repeatable (or expensive repeat), buffer via .tolist() or similar.

it formal requirement in language spec iterator blocks throw exceptions method. such, cannot rely on working. ever.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -