通过 AS3 字典高效循环 [英] Efficient looping through AS3 dictionary

查看:23
本文介绍了通过 AS3 字典高效循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)?

推荐答案

迭代 &价值观:

for (var k:Object in dictionary) {
    var value:ValType = dictionary[k];
    var key:KeyType = k;
}

更简洁地遍历:

for each (var value:ValType in dictionary) {

}

这篇关于通过 AS3 字典高效循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆