Collection (gb)
实现一个键为字符串,值为
Variant的哈希表。
NULL
被用于给定键没有关联元素时,所以,将一个键关联到
NULL
等同于将其从集合中删除。
内部哈希表的大小随数据的插入而动态增加。
属性
方法
示例
PUBLIC SUB Main()
DIM cAbbr2Weekday AS Collection = ["mo": "Monday", "tu": "Tuesday", "we": "Wednesday", "th": "Thursday", "fr": "Friday", "sa": "Saturday", "su": "Sunday"]
DIM cCopy AS Collection
DIM sAbbr AS String
' To access the data
PRINT cAbbr2Weekday["fr"]
' Print mapping key to value
FOR EACH sAbbr IN cAbbr2Weekday
PRINT cAbbr2Weekday.Key & " --> " & sAbbr
NEXT
' Lenght/Count return both 7
PRINT cAbbr2Weekday.Count
PRINT cAbbr2Weekday.Length
' Add element and remove it again
cAbbr2Weekday.Add("sat", "Saturday")
cAbbr2Weekday.Remove("sat")
' Test if a key is present
PRINT cAbbr2Weekday.Exist("we")
' Make a copy and clear the original collection
cCopy = cAbbr2Weekday.Copy()
cAbbr2Weekday.Clear()
END