views:

890

answers:

1
for (var k in dictionary) 
{
  var key:KeyType = KeyType(k);
  var value:ValType = ValType(dictionary[k]); // <-- lookup
  // do stuff
}

This is what I use to loop through the entries in a dictionary. As you can see in every iteration I perform a lookup in the dictionary. Is there a more efficient way of iterating the dictionary (while keeping access to the key)?

+1  A: 
for each (var value:ValType in dictionary) {
 // do stuff
}

since you want to know the key they is no better way:

for (var k:Object in dictionary) {
  var value:ValType=dictionary[k];
  var key:KeyType=k;
 // do stuff
}
Patrick
I need to know the key (clarified in my question)
Bart van Heukelom
Accepted because it answers the question. As a solution though, I've made a wrapper around dictionary which stores the key and value as value of its dictionary.
Bart van Heukelom