获取ActionScript 3的字典大小 [英] Get size of ActionScript 3 Dictionary

查看:497
本文介绍了获取ActionScript 3的字典大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var d:Dictionary = new Dictionary();
d["a"] = "b";
d["b"] = "z";

如何获得字典的长度/大小(2)?

How to get the length/size of the dictionary (which is 2) ?

推荐答案

有没有内置的方法来获得AS3字典的大小/ lenght /计数。 有解决方法:例如,您可以创建一个扩展或包装了 flash.utils.Dictionary 类的自定义词典类,添加计数器功能。您可以管理数作为条目添加/删除,或使用一个简单的For循环迭代按需计算:

There is no built-in method to get the size/lenght/count of an AS3 dictionary. There are workarounds: for example, you can create a custom dictionary class which extends or wraps the flash.utils.Dictionary class, adding the counter functionality. You can manage the count as entries are added/removed, or count on-demand using a simple For loop iteration:

public static function countKeys(myDictionary:flash.utils.Dictionary):int 
{
    var n:int = 0;
    for (var key:* in myDictionary) {
        n++;
    }
    return n;
}

这篇关于获取ActionScript 3的字典大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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