c# - Distinction between iterator and enumerator -


an interview question .net 3.5 job "what difference between iterator , enumerator"?

this core distinction make, linq, etc.

anyway, difference? can't seem find solid definition on net. make no mistake, can find meaning of 2 terms different answers. best answer interview?

imo iterator "iterates" on collection, , enumerator provides functionality iterate, has called.

also, using yield keyword said save state. state? there example of benefit occurring?

iterating means repeating steps, while enumerating means going through values in collection of values. enumerating requires form of iteration.

in way, enumerating special case of iterating step getting value collection.

note "usually" – enumerating may performed recursively, recursion , iteration closely related not care small difference.

you may enumerate values not explicitly store in collection. example, can enumerate natural number, primes, or whatever calculate these values during enumeration , not retrieve them physical collection. understand case enumerating virtual collection values defined logic.


i assume reed copsey got point. in c# there 2 major ways enumerate something.

  1. implement enumerable , class implementing ienumerator
  2. implement iterator yield statement

the first way harder implement , uses objects enumerating. second way easier implement , uses continuations.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -