Collection (gb)
This class implements an hash table whose keys are
String and values are
Variant.
NULL
is used when nothing is associated with a given key. Consequently, associating
NULL
with a key is the same thing as removing it from the collection.
The size of the internal hash table grows dynamically as data is inserted.
Vlastnosti
Count
|
Returns the number of elements stored in the collection.
|
Default
|
Return or set the collection default value that is returned when no value is associated with a key.
|
Empty
|
Return if the collection is empty.
|
First
|
Returns the key of the first element inserted in the collection, or NULL if the collection is void.
|
Key
|
Returns the key of the last read or last enumerated element.
|
Keys
|
Return a string array of all collection keys.
|
Last
|
Returns the key of the last element inserted in the collection, or NULL if the collection is void.
|
Length
|
Returns the number of elements stored in the collection.
|
ReadOnly
|
Return or set if the collection contents is read-only.
|
Metoda
Add
|
Adds an element to the collection.
|
Clear
|
Clears the collection.
|
Copy
|
Returns a copy of the collection.
|
Equals
|
Returns if Collection is equals to the current collection.
|
Exist
|
Returns if something is associated with this key in the collection.
|
Insert
|
Insert the contents of Collection into the current collection.
|
Remove
|
Removes an element from the collection.
|
Example
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