.net - Should a GetEnumerator method still be idempotent when the class does not implement IEnumerable -


this question piggy backs of question raised regarding abusing ienumerable interface modifying object iterate on it.

the general consensus no implements ienumerable should idempotent. .net supports compile time duck typing foreach statement. object provides ienumerator getenumerator() method can used inside foreach statement.

so should getenumerator method idempotent or when implements ienumerable?

edit (added context)

to put context round suggesting when iterating on queue each item dequeued goes. additionally new objects pushed onto queue after call getenumerator still iterated over.

it's not type idempotent - doesn't make sense; may mean immutable, that's not clear. it's getenumerator method typically idempotent.

while i'd that's typically case, can envisage special cases makes sense have non-idempotent getenumerator method. example, you've got data can read once (because it's streaming web server won't service same request again, or that). in case, getenumerator have invalidate data source, future calls throw exception.

such types , methods should documented carefully, of course, think they're reasonable.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -