获取 ActionScript 3 字典的大小 [英] Get size of ActionScript 3 Dictionary
本文介绍了获取 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 字典的大小/长度/计数.有一些变通方法:例如,您可以创建一个自定义字典类来扩展或包装 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屋!
查看全文