1

This line of code confuses me:

List<string> keys = new List<string>();
IDictionaryEnumerator ca = cache.GetEnumerator();
while (ca.MoveNext())
{
  keys.Add(ca.Key.ToString());
}

What is an Enumerator? Is it connected to Enumerations? I try to find a tutorial on enumerators, but without success. Hope someone will have patience to explain it to me.

sandalone
  • 41,141
  • 63
  • 222
  • 338
  • possible duplicate of [Can anyone explain IEnumerable and IEnumerator to me?](http://stackoverflow.com/questions/558304/can-anyone-explain-ienumerable-and-ienumerator-to-me) – Kirk Woll Oct 05 '10 at 17:26

1 Answers1

1

You don't show what type 'cache' actually is but your code is equivalent to :

foreach(var ca in cache)  
{
   keys.Add(ca.Key.ToString();
}

foreach() uses the Enumerator as well, but cleaner through compiler-generated code.

H H
  • 263,252
  • 30
  • 330
  • 514