What's Enumerator in an object?
-
28-09-2019 - |
Question
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.
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow